module Drasil.GlassBR.IMods (symb, iMods, pbIsSafe, lrIsSafe, instModIntro) where

import Prelude hiding (exp)
import Language.Drasil
import Theory.Drasil (InstanceModel, imNoDeriv, qwC, equationalModelN)
import Language.Drasil.Chunk.Concept.NamedCombinators
import qualified Language.Drasil.Sentence.Combinators as S
import Data.Drasil.SI_Units
import Drasil.GlassBR.DataDefs (probOfBreak, calofCapacity,
  pbTolUsr, qRef)
import Drasil.GlassBR.Goals (willBreakGS)
import Drasil.GlassBR.References (astm2009)
import Drasil.GlassBR.Unitals (charWeight, demand, isSafeLR, isSafePb,
  lRe, pbTol, plateLen, plateWidth, probBr, standOffDist)

import Data.Drasil.Concepts.Documentation (goal)

iMods :: [InstanceModel]
iMods :: [InstanceModel]
iMods = [InstanceModel
pbIsSafe, InstanceModel
lrIsSafe]

symb :: [UnitalChunk]
symb :: [UnitalChunk]
symb =  [UncertQ -> UnitDefn -> UnitalChunk
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> UnitDefn -> UnitalChunk
ucuc UncertQ
plateLen UnitDefn
metre, UncertQ -> UnitDefn -> UnitalChunk
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> UnitDefn -> UnitalChunk
ucuc UncertQ
plateWidth UnitDefn
metre, UncertQ -> UnitDefn -> UnitalChunk
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> UnitDefn -> UnitalChunk
ucuc UncertQ
charWeight UnitDefn
kilogram, UncertQ -> UnitDefn -> UnitalChunk
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> UnitDefn -> UnitalChunk
ucuc UncertQ
standOffDist UnitDefn
metre, UnitalChunk
demand] -- this is temporary
-- ++
 -- [dqdQd (qw calofDemand) demandq]

{--}

pbIsSafe :: InstanceModel
pbIsSafe :: InstanceModel
pbIsSafe = ModelKind Expr
-> Inputs
-> Output
-> OutputConstraints
-> [DecRef]
-> String
-> [Sentence]
-> InstanceModel
imNoDeriv (NP -> QDefinition Expr -> ModelKind Expr
forall e. NP -> QDefinition e -> ModelKind e
equationalModelN (String -> NP
nounPhraseSP "Safety Req-Pb") QDefinition Expr
pbIsSafeQD)
  [ConstrainedChunk -> RealInterval Expr Expr -> Input
forall q.
(Quantity q, MayHaveUnit q) =>
q -> RealInterval Expr Expr -> Input
qwC ConstrainedChunk
probBr (RealInterval Expr Expr -> Input)
-> RealInterval Expr Expr -> Input
forall a b. (a -> b) -> a -> b
$ (Inclusive, Expr) -> RealInterval Expr Expr
forall b a. (Inclusive, b) -> RealInterval a b
UpFrom (Inclusive
Exc, Integer -> Expr
forall r. LiteralC r => Integer -> r
exactDbl 0), UncertainChunk -> RealInterval Expr Expr -> Input
forall q.
(Quantity q, MayHaveUnit q) =>
q -> RealInterval Expr Expr -> Input
qwC UncertainChunk
pbTol (RealInterval Expr Expr -> Input)
-> RealInterval Expr Expr -> Input
forall a b. (a -> b) -> a -> b
$ (Inclusive, Expr) -> RealInterval Expr Expr
forall b a. (Inclusive, b) -> RealInterval a b
UpFrom (Inclusive
Exc, Integer -> Expr
forall r. LiteralC r => Integer -> r
exactDbl 0)]
  (Output -> Output
forall q. (Quantity q, MayHaveUnit q) => q -> Output
qw Output
isSafePb) []
  [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] "isSafePb"
  [Sentence
pbIsSafeDesc, Sentence
probBRRef, Sentence
pbTolUsr]


pbIsSafeQD :: SimpleQDef
pbIsSafeQD :: QDefinition Expr
pbIsSafeQD = Output -> Expr -> QDefinition Expr
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef Output
isSafePb (ConstrainedChunk -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrainedChunk
probBr Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$< UncertainChunk -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertainChunk
pbTol)

{--}

lrIsSafe :: InstanceModel
lrIsSafe :: InstanceModel
lrIsSafe = ModelKind Expr
-> Inputs
-> Output
-> OutputConstraints
-> [DecRef]
-> String
-> [Sentence]
-> InstanceModel
imNoDeriv (NP -> QDefinition Expr -> ModelKind Expr
forall e. NP -> QDefinition e -> ModelKind e
equationalModelN (String -> NP
nounPhraseSP "Safety Req-LR") QDefinition Expr
lrIsSafeQD)
  [UnitalChunk -> RealInterval Expr Expr -> Input
forall q.
(Quantity q, MayHaveUnit q) =>
q -> RealInterval Expr Expr -> Input
qwC UnitalChunk
lRe (RealInterval Expr Expr -> Input)
-> RealInterval Expr Expr -> Input
forall a b. (a -> b) -> a -> b
$ (Inclusive, Expr) -> RealInterval Expr Expr
forall b a. (Inclusive, b) -> RealInterval a b
UpFrom (Inclusive
Exc, Integer -> Expr
forall r. LiteralC r => Integer -> r
exactDbl 0), UnitalChunk -> RealInterval Expr Expr -> Input
forall q.
(Quantity q, MayHaveUnit q) =>
q -> RealInterval Expr Expr -> Input
qwC UnitalChunk
demand (RealInterval Expr Expr -> Input)
-> RealInterval Expr Expr -> Input
forall a b. (a -> b) -> a -> b
$ (Inclusive, Expr) -> RealInterval Expr Expr
forall b a. (Inclusive, b) -> RealInterval a b
UpFrom (Inclusive
Exc, Integer -> Expr
forall r. LiteralC r => Integer -> r
exactDbl 0)]
  (Output -> Output
forall q. (Quantity q, MayHaveUnit q) => q -> Output
qw Output
isSafeLR) []
  [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] "isSafeLR"
  [Sentence
lrIsSafeDesc, Sentence
capRef, Sentence
qRef] 

lrIsSafeQD :: SimpleQDef 
lrIsSafeQD :: QDefinition Expr
lrIsSafeQD = Output -> Expr -> QDefinition Expr
forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef Output
isSafeLR (UnitalChunk -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
lRe Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$> UnitalChunk -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
demand)

iModDesc :: QuantityDict -> Sentence -> Sentence
iModDesc :: Output -> Sentence -> Sentence
iModDesc main :: Output
main s :: Sentence
s = [Sentence] -> Sentence
foldlSent [String -> Sentence
S "If", Output -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch Output
main Sentence -> Sentence -> Sentence
`sC` String -> Sentence
S "the glass is" Sentence -> Sentence -> Sentence
+:+.
    String -> Sentence
S "considered safe", Sentence
s Sentence -> Sentence -> Sentence
`S.are` String -> Sentence
S "either both True or both False"]
  
-- Intro --

instModIntro :: Sentence
instModIntro :: Sentence
instModIntro = [Sentence] -> Sentence
foldlSent [NP -> Sentence
forall n. NounPhrase n => n -> Sentence
atStartNP (NamedChunk -> NP
forall t. NamedIdea t => t -> NP
the NamedChunk
goal), ConceptInstance -> Sentence
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS ConceptInstance
willBreakGS, 
  String -> Sentence
S "is met by", InstanceModel -> Sentence
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS InstanceModel
pbIsSafe Sentence -> Sentence -> Sentence
`sC` InstanceModel -> Sentence
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS InstanceModel
lrIsSafe]

-- Notes --

capRef :: Sentence
capRef :: Sentence
capRef = DataDefinition -> Sentence -> Sentence
forall r.
(Referable r, HasShortName r, HasSymbol r) =>
r -> Sentence -> Sentence
definedIn' DataDefinition
calofCapacity (String -> Sentence
S "and is also called capacity")

lrIsSafeDesc :: Sentence
lrIsSafeDesc :: Sentence
lrIsSafeDesc = Output -> Sentence -> Sentence
iModDesc Output
isSafeLR
  (Output -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch Output
isSafePb Sentence -> Sentence -> Sentence
+:+ InstanceModel -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource InstanceModel
pbIsSafe Sentence -> Sentence -> Sentence
`S.and_` Output -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch Output
isSafeLR)

pbIsSafeDesc :: Sentence
pbIsSafeDesc :: Sentence
pbIsSafeDesc = Output -> Sentence -> Sentence
iModDesc Output
isSafePb
  (Output -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch Output
isSafePb Sentence -> Sentence -> Sentence
`S.and_` Output -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch Output
isSafePb Sentence -> Sentence -> Sentence
+:+ InstanceModel -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource InstanceModel
lrIsSafe)

probBRRef :: Sentence
probBRRef :: Sentence
probBRRef = DataDefinition -> Sentence
forall r.
(Referable r, HasShortName r, HasSymbol r) =>
r -> Sentence
definedIn DataDefinition
probOfBreak