{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoImplicitPrelude #-}

module Data.Morpheus.Client.Internal.Types
  ( ClientTypeDefinition (..),
    TypeNameTH (..),
    FetchDefinition (..),
    ClientConstructorDefinition (..),
    FetchError (..),
    SchemaSource (..),
    ExecutableSource,
  )
where

import Data.ByteString.Lazy (ByteString)
import Data.Morpheus.Types.Internal.AST
  ( ANY,
    FieldDefinition,
    FieldName,
    GQLErrors,
    TypeKind,
    TypeName,
    VALID,
  )
import Relude hiding (ByteString)

data TypeNameTH = TypeNameTH
  { TypeNameTH -> [FieldName]
namespace :: [FieldName],
    TypeNameTH -> TypeName
typename :: TypeName
  }
  deriving (Int -> TypeNameTH -> ShowS
[TypeNameTH] -> ShowS
TypeNameTH -> String
(Int -> TypeNameTH -> ShowS)
-> (TypeNameTH -> String)
-> ([TypeNameTH] -> ShowS)
-> Show TypeNameTH
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypeNameTH] -> ShowS
$cshowList :: [TypeNameTH] -> ShowS
show :: TypeNameTH -> String
$cshow :: TypeNameTH -> String
showsPrec :: Int -> TypeNameTH -> ShowS
$cshowsPrec :: Int -> TypeNameTH -> ShowS
Show)

data ClientConstructorDefinition = ClientConstructorDefinition
  { ClientConstructorDefinition -> TypeName
cName :: TypeName,
    ClientConstructorDefinition -> [FieldDefinition ANY VALID]
cFields :: [FieldDefinition ANY VALID]
  }
  deriving (Int -> ClientConstructorDefinition -> ShowS
[ClientConstructorDefinition] -> ShowS
ClientConstructorDefinition -> String
(Int -> ClientConstructorDefinition -> ShowS)
-> (ClientConstructorDefinition -> String)
-> ([ClientConstructorDefinition] -> ShowS)
-> Show ClientConstructorDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientConstructorDefinition] -> ShowS
$cshowList :: [ClientConstructorDefinition] -> ShowS
show :: ClientConstructorDefinition -> String
$cshow :: ClientConstructorDefinition -> String
showsPrec :: Int -> ClientConstructorDefinition -> ShowS
$cshowsPrec :: Int -> ClientConstructorDefinition -> ShowS
Show)

data ClientTypeDefinition = ClientTypeDefinition
  { ClientTypeDefinition -> TypeNameTH
clientTypeName :: TypeNameTH,
    ClientTypeDefinition -> [ClientConstructorDefinition]
clientCons :: [ClientConstructorDefinition],
    ClientTypeDefinition -> TypeKind
clientKind :: TypeKind
  }
  deriving (Int -> ClientTypeDefinition -> ShowS
[ClientTypeDefinition] -> ShowS
ClientTypeDefinition -> String
(Int -> ClientTypeDefinition -> ShowS)
-> (ClientTypeDefinition -> String)
-> ([ClientTypeDefinition] -> ShowS)
-> Show ClientTypeDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientTypeDefinition] -> ShowS
$cshowList :: [ClientTypeDefinition] -> ShowS
show :: ClientTypeDefinition -> String
$cshow :: ClientTypeDefinition -> String
showsPrec :: Int -> ClientTypeDefinition -> ShowS
$cshowsPrec :: Int -> ClientTypeDefinition -> ShowS
Show)

data FetchDefinition = FetchDefinition
  { FetchDefinition -> TypeNameTH
rootTypeName :: TypeNameTH,
    FetchDefinition -> Maybe TypeNameTH
clientArgumentsTypeName :: Maybe TypeNameTH
  }
  deriving (Int -> FetchDefinition -> ShowS
[FetchDefinition] -> ShowS
FetchDefinition -> String
(Int -> FetchDefinition -> ShowS)
-> (FetchDefinition -> String)
-> ([FetchDefinition] -> ShowS)
-> Show FetchDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FetchDefinition] -> ShowS
$cshowList :: [FetchDefinition] -> ShowS
show :: FetchDefinition -> String
$cshow :: FetchDefinition -> String
showsPrec :: Int -> FetchDefinition -> ShowS
$cshowsPrec :: Int -> FetchDefinition -> ShowS
Show)

data FetchError a
  = FetchErrorParseFailure String
  | FetchErrorProducedErrors GQLErrors (Maybe a)
  | FetchErrorNoResult
  deriving (Int -> FetchError a -> ShowS
[FetchError a] -> ShowS
FetchError a -> String
(Int -> FetchError a -> ShowS)
-> (FetchError a -> String)
-> ([FetchError a] -> ShowS)
-> Show (FetchError a)
forall a. Show a => Int -> FetchError a -> ShowS
forall a. Show a => [FetchError a] -> ShowS
forall a. Show a => FetchError a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FetchError a] -> ShowS
$cshowList :: forall a. Show a => [FetchError a] -> ShowS
show :: FetchError a -> String
$cshow :: forall a. Show a => FetchError a -> String
showsPrec :: Int -> FetchError a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> FetchError a -> ShowS
Show, FetchError a -> FetchError a -> Bool
(FetchError a -> FetchError a -> Bool)
-> (FetchError a -> FetchError a -> Bool) -> Eq (FetchError a)
forall a. Eq a => FetchError a -> FetchError a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FetchError a -> FetchError a -> Bool
$c/= :: forall a. Eq a => FetchError a -> FetchError a -> Bool
== :: FetchError a -> FetchError a -> Bool
$c== :: forall a. Eq a => FetchError a -> FetchError a -> Bool
Eq, (forall x. FetchError a -> Rep (FetchError a) x)
-> (forall x. Rep (FetchError a) x -> FetchError a)
-> Generic (FetchError a)
forall x. Rep (FetchError a) x -> FetchError a
forall x. FetchError a -> Rep (FetchError a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (FetchError a) x -> FetchError a
forall a x. FetchError a -> Rep (FetchError a) x
$cto :: forall a x. Rep (FetchError a) x -> FetchError a
$cfrom :: forall a x. FetchError a -> Rep (FetchError a) x
Generic)

data SchemaSource
  = JSON ByteString
  | GQL ByteString
  deriving (Int -> SchemaSource -> ShowS
[SchemaSource] -> ShowS
SchemaSource -> String
(Int -> SchemaSource -> ShowS)
-> (SchemaSource -> String)
-> ([SchemaSource] -> ShowS)
-> Show SchemaSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SchemaSource] -> ShowS
$cshowList :: [SchemaSource] -> ShowS
show :: SchemaSource -> String
$cshow :: SchemaSource -> String
showsPrec :: Int -> SchemaSource -> ShowS
$cshowsPrec :: Int -> SchemaSource -> ShowS
Show, SchemaSource -> SchemaSource -> Bool
(SchemaSource -> SchemaSource -> Bool)
-> (SchemaSource -> SchemaSource -> Bool) -> Eq SchemaSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SchemaSource -> SchemaSource -> Bool
$c/= :: SchemaSource -> SchemaSource -> Bool
== :: SchemaSource -> SchemaSource -> Bool
$c== :: SchemaSource -> SchemaSource -> Bool
Eq)

type ExecutableSource = Text