keiro-dsl-0.10.0.0: test/conformance-scalar-expressions/Generated/AggregateScalarExpressions/Nominals.hs
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TypeFamilies #-}
-- @generated by keiro-dsl 0.9.0.0 (language keiro-dsl 4) from context aggregate-scalar-expressions generated nominal declarations; do not edit.
module Generated.AggregateScalarExpressions.Nominals
( AccountMode (..)
, accountModeText
, AccountModeEqualityProjection
, accountModeEqualityWitness
, RequestId
, parseRequestId
, mkRequestId
, requestIdText
, RequestIdEqualityProjection
, requestIdEqualityWitness
) where
import Data.Aeson (FromJSON, ToJSON)
import Data.Text (Text)
import GHC.Generics (Generic)
import Keiki.Shape (CanonicalTypeName)
import Generated.AggregateScalarExpressions.Nominals.Internal (RequestId, mkRequestId, parseRequestId, requestIdText)
import Keiki.Core (ExactFieldProjection (..), FieldProjection (..), FieldWitness, exactFieldWitness, fieldWitness)
import Data.List.NonEmpty (NonEmpty (..))
import Keiki.ProjectionDomain (TextPattern, finiteProjectionDomain, textProjectionDomain)
import Keiro.Codec.IdDomain (idDomainTextPattern, typeIdV7Domain)
data AccountMode = Normal | Restricted
deriving stock (Generic, Eq, Ord, Show, Enum, Bounded)
deriving anyclass (ToJSON, FromJSON)
instance CanonicalTypeName AccountMode
accountModeText :: AccountMode -> Text
accountModeText = \case
Normal -> "normal"
Restricted -> "restricted"
data AccountModeEqualityProjection
instance FieldProjection AccountModeEqualityProjection where
type FieldName AccountModeEqualityProjection = "AccountMode"
type FieldOwner AccountModeEqualityProjection = AccountMode
type FieldResult AccountModeEqualityProjection = Text
fieldShapeId _ = "nominal-equality|name=AccountMode|contract=keiro-dsl/nominal-equality/1|key=Text|domain=finite-text:normal,restricted|owner=generated"
projectFieldValue _ = accountModeText
instance ExactFieldProjection AccountModeEqualityProjection where
fieldProjectionDomain _ = finiteProjectionDomain ("normal" :| ["restricted"])
reconstructFieldOwner _ = \case
"normal" -> Just Normal
"restricted" -> Just Restricted
_ -> Nothing
accountModeEqualityWitness :: FieldWitness AccountModeEqualityProjection
accountModeEqualityWitness = exactFieldWitness @AccountModeEqualityProjection
instance CanonicalTypeName RequestId
data RequestIdEqualityProjection
instance FieldProjection RequestIdEqualityProjection where
type FieldName RequestIdEqualityProjection = "RequestId"
type FieldOwner RequestIdEqualityProjection = RequestId
type FieldResult RequestIdEqualityProjection = Text
fieldShapeId _ = "nominal-equality|name=RequestId|contract=keiro-dsl/nominal-equality/2|key=Text|domain=typeid-v7-text:req:keiro-dsl/id-domain/typeid-v7/1|owner=generated"
projectFieldValue _ = requestIdText
requestIdIdDomainPattern :: TextPattern
requestIdIdDomainPattern = either (error . show) id (idDomainTextPattern (typeIdV7Domain "req"))
instance ExactFieldProjection RequestIdEqualityProjection where
fieldProjectionDomain _ = textProjectionDomain requestIdIdDomainPattern
reconstructFieldOwner _ = either (const Nothing) Just . parseRequestId
requestIdEqualityWitness :: FieldWitness RequestIdEqualityProjection
requestIdEqualityWitness = exactFieldWitness @RequestIdEqualityProjection