keiro-dsl-0.17.0.0: test/conformance-structural-nominals/Generated/StructuralNominalLeaves/TemplateWork/Queue.hs
-- @generated by keiro-dsl 0.17.0.0 (language keiro-dsl 6) from workqueue template_work; do not edit.
module Generated.StructuralNominalLeaves.TemplateWork.Queue
( TemplateWork (..)
, encodeTemplateWork
, parseTemplateWork
, queuePhysical, queueDlq, queueTable
) where
import Data.Aeson (Value (..), object, withObject, (.=))
import Data.Aeson.Types (explicitParseField, parseEither)
import Data.Text (Text)
import qualified Data.Text as T
import Generated.StructuralNominalLeaves.Structural.NominalLeaves (encodeClaimIdLeaf, parseClaimIdLeaf, encodeTemplateIdLeaf, parseTemplateIdLeaf)
import Conformance.StructuralNominals.Domain (ClaimId)
import Generated.StructuralNominalLeaves.Nominals (TemplateId)
queuePhysical, queueDlq, queueTable :: Text
queuePhysical = "template_work"
queueDlq = "template_work_dlq"
queueTable = "pgmq.q_template_work"
data TemplateWork = TemplateWork
{ templateId :: !TemplateId
, holder :: !(Maybe ClaimId)
}
deriving stock (Eq, Show)
encodeTemplateWork :: TemplateWork -> Value
encodeTemplateWork payload =
object
[ "template_id" .= encodeTemplateIdLeaf payload.templateId
, "holder" .= maybe Null (\item0 -> encodeClaimIdLeaf item0) (payload.holder)
]
parseTemplateWork :: Value -> Either Text TemplateWork
parseTemplateWork = mapLeftText . parseEither (withObject "TemplateWork" go)
where
go objectValue = TemplateWork <$> explicitParseField (parseTemplateIdLeaf) objectValue "template_id" <*> explicitParseField (\value0 -> case value0 of Null -> pure Nothing; other0 -> Just <$> (parseClaimIdLeaf) other0) objectValue "holder"
mapLeftText :: Either String b -> Either Text b
mapLeftText = either (Left . T.pack) Right