{-#LANGUAGE CPP #-}
module Twilio.Types.SID.TH
( createSID
) where
import Data.Monoid ((<>))
import Language.Haskell.TH
#if MIN_VERSION_template_haskell(2,11,0)
( Bang(..)
, SourceStrictness(..)
, SourceUnpackedness(..)
#else
( Strict(..)
#endif
#if MIN_VERSION_template_haskell(2,12,0)
, DerivClause(..)
#endif
, Body(..)
, Clause(..)
, Con(..)
, Dec(..)
, DecsQ
, Exp(..)
, Pat(..)
, Type(..)
, mkName
)
import Twilio.Types.Alpha (Alpha)
createSID
:: Alpha
-> Alpha
-> String
-> DecsQ
createSID a b resource = pure
(
[ newtypeDeclaration
]
<> smartConstructor
)
where
#if MIN_VERSION_template_haskell(2,11,0)
derivedClasses = map (ConT . mkName)
#else
derivedClasses = map mkName
#endif
[ "Bounded"
, "Data"
, "Eq"
, "FromJSON"
, "Generic"
, "Hashable"
, "IsSID"
, "IsString"
, "Ix"
, "NFData"
, "Ord"
, "Read"
, "Show"
, "ToJSON"
, "Typeable"
]
getSID = mkName $ "get" <> resource <> "SID"
makeSID = mkName $ resource <> "SID"
newtypeDeclaration = NewtypeD [] makeSID []
#if MIN_VERSION_template_haskell(2,11,0)
Nothing
#endif
(RecC makeSID
[ ( getSID
#if MIN_VERSION_template_haskell(2,11,0)
, Bang NoSourceUnpackedness NoSourceStrictness
#else
, NotStrict
#endif
, sidType
)
]
)
#if MIN_VERSION_template_haskell(2,12,0)
[DerivClause Nothing derivedClasses]
#else
derivedClasses
#endif
sidType = AppT
(AppT (ConT $ mkName "SID")
(PromotedT . mkName $ show a))
(PromotedT . mkName $ show b)
smartConstructor =
[ SigD (mkName $ "mk" <> resource <> "SID")
(AppT
(AppT
ArrowT
(ConT $ mkName "Word64"))
(AppT
(AppT
ArrowT
(ConT $ mkName "Word64"))
(ConT makeSID)))
, FunD (mkName $ "mk" <> resource <> "SID")
[ Clause [VarP $ mkName "word1", VarP $ mkName "word2"]
(NormalB (AppE (ConE makeSID)
(AppE (AppE (ConE $ mkName "SID")
(VarE $ mkName "word1"))
(VarE $ mkName "word2"))))
[]
]
]