packages feed

keiro-dsl-0.22.0.0: test/conformance-structural/Generated/StructuralConformance/StructuralProjections.hs

{-# LANGUAGE TypeFamilies #-}
-- @generated by keiro-dsl 0.22.0.0 (language keiro-dsl 4) from context structural-conformance mapped structural facade; do not edit.
-- Equality witnesses are emitted for Text, Int, Bool, Natural, and UTCTime.
-- Nominal ID and enum leaves carry exact canonical-text domains.
-- Int, Natural, and UTCTime belong to Keiki's ordered subset.
module Generated.StructuralConformance.StructuralProjections
  ( artifactInfoArtifactKeyWitness
  , artifactInfoArtifactKeyGet
  , artifactInfoDisplayNameWitness
  , artifactInfoDisplayNameGet
  , artifactKindWitness
  , artifactKindGet
  ) where

import Data.Text (Text)
import Data.List.NonEmpty (NonEmpty (..))
import Keiro.Codec.Structural (bindingToShape, bindingFromShape)
import Keiki.Core (FieldProjection (..), FieldWitness, ExactFieldProjection (..), exactFieldWitness, fieldWitness)
import Keiki.ProjectionDomain (finiteProjectionDomain)
import Generated.StructuralConformance.Structural.Shape.ArtifactInfo (ArtifactInfoShape(artifactKey, displayName))
import Conformance.Structural.Bindings qualified as Bindings
import Conformance.Structural.Domain (ArtifactInfo, ArtifactKind)
import Generated.StructuralConformance.Structural.Shape.ArtifactKind qualified as ShapeArtifactKind

data ArtifactInfoArtifactKeyProjection

artifactInfoArtifactKeyGet :: ArtifactInfo -> Text
artifactInfoArtifactKeyGet owner = (bindingToShape Bindings.artifactInfoBinding owner).artifactKey

instance FieldProjection ArtifactInfoArtifactKeyProjection where
  type FieldName ArtifactInfoArtifactKeyProjection = "/artifact_key"
  type FieldOwner ArtifactInfoArtifactKeyProjection = ArtifactInfo
  type FieldResult ArtifactInfoArtifactKeyProjection = Text
  fieldShapeId _ = "conformance.structural.ArtifactInfo.v1"
  projectFieldValue _ = artifactInfoArtifactKeyGet

artifactInfoArtifactKeyWitness :: FieldWitness ArtifactInfoArtifactKeyProjection
artifactInfoArtifactKeyWitness = fieldWitness @ArtifactInfoArtifactKeyProjection

data ArtifactInfoDisplayNameProjection

artifactInfoDisplayNameGet :: ArtifactInfo -> Text
artifactInfoDisplayNameGet owner = (bindingToShape Bindings.artifactInfoBinding owner).displayName

instance FieldProjection ArtifactInfoDisplayNameProjection where
  type FieldName ArtifactInfoDisplayNameProjection = "/display_name"
  type FieldOwner ArtifactInfoDisplayNameProjection = ArtifactInfo
  type FieldResult ArtifactInfoDisplayNameProjection = Text
  fieldShapeId _ = "conformance.structural.ArtifactInfo.v1"
  projectFieldValue _ = artifactInfoDisplayNameGet

artifactInfoDisplayNameWitness :: FieldWitness ArtifactInfoDisplayNameProjection
artifactInfoDisplayNameWitness = fieldWitness @ArtifactInfoDisplayNameProjection

data ArtifactKindProjection

artifactKindGet :: ArtifactKind -> Text
artifactKindGet owner = case bindingToShape Bindings.artifactKindBinding owner of ShapeArtifactKind.Guide -> "guide"; ShapeArtifactKind.Reference -> "reference"

instance FieldProjection ArtifactKindProjection where
  type FieldName ArtifactKindProjection = ""
  type FieldOwner ArtifactKindProjection = ArtifactKind
  type FieldResult ArtifactKindProjection = Text
  fieldShapeId _ = "conformance.structural.ArtifactKind.v1"
  projectFieldValue _ = artifactKindGet

instance ExactFieldProjection ArtifactKindProjection where
  fieldProjectionDomain _ = finiteProjectionDomain ("guide" :| ["reference"])
  reconstructFieldOwner _ value = case value of
    "guide" -> Just (bindingFromShape Bindings.artifactKindBinding ShapeArtifactKind.Guide)
    "reference" -> Just (bindingFromShape Bindings.artifactKindBinding ShapeArtifactKind.Reference)
    _ -> Nothing

artifactKindWitness :: FieldWitness ArtifactKindProjection
artifactKindWitness = exactFieldWitness @ArtifactKindProjection