{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}

module Data.Morpheus.Server.Deriving.Schema.TypeContent
  ( buildTypeContent,
  )
where

import Data.Morpheus.Server.Deriving.Schema.Enum
  ( buildEnumTypeContent,
  )
import Data.Morpheus.Server.Deriving.Schema.Internal
  ( KindedType (..),
    TyContent,
  )
import Data.Morpheus.Server.Deriving.Schema.Object
  ( buildObjectTypeContent,
  )
import Data.Morpheus.Server.Deriving.Schema.Union (buildUnionTypeContent)
import Data.Morpheus.Server.Deriving.Utils
  ( ConsRep (..),
    isEmptyConstraint,
  )
import Data.Morpheus.Server.Deriving.Utils.Kinded
  ( CategoryValue (..),
  )
import Data.Morpheus.Server.Types.GQLType (GQLType)
import Data.Morpheus.Server.Types.SchemaT (SchemaT)
import Data.Morpheus.Types.Internal.AST

buildTypeContent ::
  (GQLType a, CategoryValue kind) =>
  KindedType kind a ->
  [ConsRep (TyContent kind)] ->
  SchemaT kind (TypeContent TRUE kind CONST)
buildTypeContent :: forall a (kind :: TypeCategory).
(GQLType a, CategoryValue kind) =>
KindedType kind a
-> [ConsRep (TyContent kind)]
-> SchemaT kind (TypeContent TRUE kind CONST)
buildTypeContent KindedType kind a
scope [ConsRep (TyContent kind)]
cons | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall a. ConsRep a -> Bool
isEmptyConstraint [ConsRep (TyContent kind)]
cons = forall a (kind :: TypeCategory) (c :: TypeCategory).
GQLType a =>
KindedType kind a
-> [TypeName] -> SchemaT c (TypeContent TRUE kind CONST)
buildEnumTypeContent KindedType kind a
scope (forall v. ConsRep v -> TypeName
consName forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ConsRep (TyContent kind)]
cons)
buildTypeContent KindedType kind a
scope [ConsRep {[FieldRep (TyContent kind)]
consFields :: forall v. ConsRep v -> [FieldRep v]
consFields :: [FieldRep (TyContent kind)]
consFields}] = forall (f :: * -> *) a (cat :: TypeCategory).
(Applicative f, GQLType a) =>
KindedType cat a
-> [FieldRep (Maybe (FieldContent TRUE cat CONST))]
-> f (TypeContent TRUE cat CONST)
buildObjectTypeContent KindedType kind a
scope [FieldRep (TyContent kind)]
consFields
buildTypeContent KindedType kind a
scope [ConsRep (TyContent kind)]
cons = forall a (kind :: TypeCategory) (c :: TypeCategory).
(GQLType a, CategoryValue kind) =>
KindedType kind a
-> [ConsRep (Maybe (FieldContent TRUE kind CONST))]
-> SchemaT c (TypeContent TRUE kind CONST)
buildUnionTypeContent KindedType kind a
scope [ConsRep (TyContent kind)]
cons