packages feed

keiro-dsl-0.7.0.0: test/conformance-scalar-expressions/Generated/AggregateScalarExpressions/Nominals.hs

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
-- @generated by keiro-dsl; do not edit. Regenerated from the .keiro spec.
module Generated.AggregateScalarExpressions.Nominals where

import Data.Aeson (FromJSON, ToJSON)
import Data.Text (Text)
import GHC.Generics (Generic)
import Keiki.Shape (CanonicalTypeName)
import Keiki.Core (ExactFieldProjection (..), FieldProjection (..), FieldWitness, exactFieldWitness, fieldWitness)
import Data.List.NonEmpty (NonEmpty (..))
import Keiki.ProjectionDomain (finiteProjectionDomain)

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

newtype RequestId = RequestId Text
  deriving stock (Generic, Eq, Ord, Show)
  deriving anyclass (ToJSON, FromJSON)

instance CanonicalTypeName RequestId

requestIdText :: RequestId -> Text
requestIdText (RequestId value) = value

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/1|key=Text|domain=legacy-unrestricted-text|owner=generated"
  projectFieldValue _ = requestIdText

requestIdEqualityWitness :: FieldWitness RequestIdEqualityProjection
requestIdEqualityWitness = fieldWitness @RequestIdEqualityProjection