{-# LANGUAGE TemplateHaskell #-}
-- | Named arguments used in generating code.
module Language.Drasil.Chunk.NamedArgument (
  -- * Chunk Type
  NamedArgument(..),
  -- * Constructor
  narg) where

import Language.Drasil (HasSpace(..), HasSymbol(..), HasUID(..),
  Idea(..), MayHaveUnit(..), NamedIdea(..), Quantity, IsArgumentName,
  DefinedQuantityDict, Concept, dqdWr, Definition (defn), ConceptDomain (cdom))

import Control.Lens ((^.), makeLenses, view)

-- | Any quantity can be a named argument (wrapper for 'DefinedQuantityDict'),
-- but with more of a focus on generating code arguments.
newtype NamedArgument = NA {NamedArgument -> DefinedQuantityDict
_qtd :: DefinedQuantityDict}
makeLenses ''NamedArgument

-- | Finds the 'UID' of the 'DefinedQuantityDict' used to make the 'NamedArgument'.
instance HasUID         NamedArgument where uid :: Getter NamedArgument UID
uid = (DefinedQuantityDict -> f DefinedQuantityDict)
-> NamedArgument -> f NamedArgument
Iso' NamedArgument DefinedQuantityDict
qtd ((DefinedQuantityDict -> f DefinedQuantityDict)
 -> NamedArgument -> f NamedArgument)
-> ((UID -> f UID) -> DefinedQuantityDict -> f DefinedQuantityDict)
-> (UID -> f UID)
-> NamedArgument
-> f NamedArgument
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UID -> f UID) -> DefinedQuantityDict -> f DefinedQuantityDict
forall c. HasUID c => Getter c UID
Getter DefinedQuantityDict UID
uid
-- | Finds the term ('NP') of the 'DefinedQuantityDict' used to make the 'NamedArgument'.
instance NamedIdea      NamedArgument where term :: Lens' NamedArgument NP
term = (DefinedQuantityDict -> f DefinedQuantityDict)
-> NamedArgument -> f NamedArgument
Iso' NamedArgument DefinedQuantityDict
qtd ((DefinedQuantityDict -> f DefinedQuantityDict)
 -> NamedArgument -> f NamedArgument)
-> ((NP -> f NP) -> DefinedQuantityDict -> f DefinedQuantityDict)
-> (NP -> f NP)
-> NamedArgument
-> f NamedArgument
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NP -> f NP) -> DefinedQuantityDict -> f DefinedQuantityDict
forall c. NamedIdea c => Lens' c NP
Lens' DefinedQuantityDict NP
term
-- | Finds the idea contained in the 'DefinedQuantityDict' used to make the 'NamedArgument'.
instance Idea           NamedArgument where getA :: NamedArgument -> Maybe String
getA = DefinedQuantityDict -> Maybe String
forall c. Idea c => c -> Maybe String
getA (DefinedQuantityDict -> Maybe String)
-> (NamedArgument -> DefinedQuantityDict)
-> NamedArgument
-> Maybe String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting DefinedQuantityDict NamedArgument DefinedQuantityDict
-> NamedArgument -> DefinedQuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting DefinedQuantityDict NamedArgument DefinedQuantityDict
Iso' NamedArgument DefinedQuantityDict
qtd

instance Definition     NamedArgument where defn :: Lens' NamedArgument Sentence
defn = (DefinedQuantityDict -> f DefinedQuantityDict)
-> NamedArgument -> f NamedArgument
Iso' NamedArgument DefinedQuantityDict
qtd ((DefinedQuantityDict -> f DefinedQuantityDict)
 -> NamedArgument -> f NamedArgument)
-> ((Sentence -> f Sentence)
    -> DefinedQuantityDict -> f DefinedQuantityDict)
-> (Sentence -> f Sentence)
-> NamedArgument
-> f NamedArgument
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sentence -> f Sentence)
-> DefinedQuantityDict -> f DefinedQuantityDict
forall c. Definition c => Lens' c Sentence
Lens' DefinedQuantityDict Sentence
defn

instance ConceptDomain  NamedArgument where cdom :: NamedArgument -> [UID]
cdom = DefinedQuantityDict -> [UID]
forall c. ConceptDomain c => c -> [UID]
cdom (DefinedQuantityDict -> [UID])
-> (NamedArgument -> DefinedQuantityDict) -> NamedArgument -> [UID]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting DefinedQuantityDict NamedArgument DefinedQuantityDict
-> NamedArgument -> DefinedQuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting DefinedQuantityDict NamedArgument DefinedQuantityDict
Iso' NamedArgument DefinedQuantityDict
qtd
-- | Finds the 'Space' of the 'DefinedQuantityDict' used to make the 'NamedArgument'.
instance HasSpace       NamedArgument where typ :: Getter NamedArgument Space
typ = (DefinedQuantityDict -> f DefinedQuantityDict)
-> NamedArgument -> f NamedArgument
Iso' NamedArgument DefinedQuantityDict
qtd ((DefinedQuantityDict -> f DefinedQuantityDict)
 -> NamedArgument -> f NamedArgument)
-> ((Space -> f Space)
    -> DefinedQuantityDict -> f DefinedQuantityDict)
-> (Space -> f Space)
-> NamedArgument
-> f NamedArgument
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Space -> f Space) -> DefinedQuantityDict -> f DefinedQuantityDict
forall c. HasSpace c => Getter c Space
Getter DefinedQuantityDict Space
typ
-- | Finds the 'Symbol' of the 'DefinedQuantityDict' used to make the 'NamedArgument'.
instance HasSymbol      NamedArgument where symbol :: NamedArgument -> Stage -> Symbol
symbol = DefinedQuantityDict -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol (DefinedQuantityDict -> Stage -> Symbol)
-> (NamedArgument -> DefinedQuantityDict)
-> NamedArgument
-> Stage
-> Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting DefinedQuantityDict NamedArgument DefinedQuantityDict
-> NamedArgument -> DefinedQuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting DefinedQuantityDict NamedArgument DefinedQuantityDict
Iso' NamedArgument DefinedQuantityDict
qtd
-- | 'NamedArgument's have a 'Quantity'.
instance Quantity       NamedArgument where
-- | 'NamedArgument's have an argument name.
instance IsArgumentName NamedArgument where
-- | Equal if 'UID's are equal.
instance Eq             NamedArgument where NamedArgument
a == :: NamedArgument -> NamedArgument -> Bool
== NamedArgument
b = (NamedArgument
a NamedArgument -> Getting UID NamedArgument UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID NamedArgument UID
forall c. HasUID c => Getter c UID
Getter NamedArgument UID
uid) UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== (NamedArgument
b NamedArgument -> Getting UID NamedArgument UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID NamedArgument UID
forall c. HasUID c => Getter c UID
Getter NamedArgument UID
uid)
-- | Finds the units of the 'DefinedQuantityDict' used to make the 'NamedArgument'.
instance MayHaveUnit    NamedArgument where getUnit :: NamedArgument -> Maybe UnitDefn
getUnit = DefinedQuantityDict -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit (DefinedQuantityDict -> Maybe UnitDefn)
-> (NamedArgument -> DefinedQuantityDict)
-> NamedArgument
-> Maybe UnitDefn
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting DefinedQuantityDict NamedArgument DefinedQuantityDict
-> NamedArgument -> DefinedQuantityDict
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting DefinedQuantityDict NamedArgument DefinedQuantityDict
Iso' NamedArgument DefinedQuantityDict
qtd

-- | Smart constructor for 'NamedArgument' .
narg :: (Quantity q, MayHaveUnit q, Concept q) => q -> NamedArgument
narg :: forall q.
(Quantity q, MayHaveUnit q, Concept q) =>
q -> NamedArgument
narg = DefinedQuantityDict -> NamedArgument
NA (DefinedQuantityDict -> NamedArgument)
-> (q -> DefinedQuantityDict) -> q -> NamedArgument
forall b c a. (b -> c) -> (a -> b) -> a -> c
. q -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr