-- | Common types shared between similar logical model resolvers.
module Hasura.LogicalModelResolver.Types
  ( ArgumentName (..),
    NullableScalarType (..),
    nullableScalarTypeMapCodec,
  )
where

import Autodocodec (HasCodec (codec), dimapCodec)
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
import Hasura.Base.ErrorValue (squote)
import Hasura.Base.ToErrorValue
import Hasura.LogicalModel.NullableScalarType
import Hasura.Prelude hiding (first)

-- | A name of an argument to a native query or stored procedure.
newtype ArgumentName = ArgumentName
  { ArgumentName -> Text
getArgumentName :: Text
  }
  deriving newtype (ArgumentName -> ArgumentName -> Bool
(ArgumentName -> ArgumentName -> Bool)
-> (ArgumentName -> ArgumentName -> Bool) -> Eq ArgumentName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ArgumentName -> ArgumentName -> Bool
== :: ArgumentName -> ArgumentName -> Bool
$c/= :: ArgumentName -> ArgumentName -> Bool
/= :: ArgumentName -> ArgumentName -> Bool
Eq, Eq ArgumentName
Eq ArgumentName
-> (ArgumentName -> ArgumentName -> Ordering)
-> (ArgumentName -> ArgumentName -> Bool)
-> (ArgumentName -> ArgumentName -> Bool)
-> (ArgumentName -> ArgumentName -> Bool)
-> (ArgumentName -> ArgumentName -> Bool)
-> (ArgumentName -> ArgumentName -> ArgumentName)
-> (ArgumentName -> ArgumentName -> ArgumentName)
-> Ord ArgumentName
ArgumentName -> ArgumentName -> Bool
ArgumentName -> ArgumentName -> Ordering
ArgumentName -> ArgumentName -> ArgumentName
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ArgumentName -> ArgumentName -> Ordering
compare :: ArgumentName -> ArgumentName -> Ordering
$c< :: ArgumentName -> ArgumentName -> Bool
< :: ArgumentName -> ArgumentName -> Bool
$c<= :: ArgumentName -> ArgumentName -> Bool
<= :: ArgumentName -> ArgumentName -> Bool
$c> :: ArgumentName -> ArgumentName -> Bool
> :: ArgumentName -> ArgumentName -> Bool
$c>= :: ArgumentName -> ArgumentName -> Bool
>= :: ArgumentName -> ArgumentName -> Bool
$cmax :: ArgumentName -> ArgumentName -> ArgumentName
max :: ArgumentName -> ArgumentName -> ArgumentName
$cmin :: ArgumentName -> ArgumentName -> ArgumentName
min :: ArgumentName -> ArgumentName -> ArgumentName
Ord, Int -> ArgumentName -> ShowS
[ArgumentName] -> ShowS
ArgumentName -> String
(Int -> ArgumentName -> ShowS)
-> (ArgumentName -> String)
-> ([ArgumentName] -> ShowS)
-> Show ArgumentName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ArgumentName -> ShowS
showsPrec :: Int -> ArgumentName -> ShowS
$cshow :: ArgumentName -> String
show :: ArgumentName -> String
$cshowList :: [ArgumentName] -> ShowS
showList :: [ArgumentName] -> ShowS
Show, Eq ArgumentName
Eq ArgumentName
-> (Int -> ArgumentName -> Int)
-> (ArgumentName -> Int)
-> Hashable ArgumentName
Int -> ArgumentName -> Int
ArgumentName -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> ArgumentName -> Int
hashWithSalt :: Int -> ArgumentName -> Int
$chash :: ArgumentName -> Int
hash :: ArgumentName -> Int
Hashable)
  deriving stock ((forall x. ArgumentName -> Rep ArgumentName x)
-> (forall x. Rep ArgumentName x -> ArgumentName)
-> Generic ArgumentName
forall x. Rep ArgumentName x -> ArgumentName
forall x. ArgumentName -> Rep ArgumentName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ArgumentName -> Rep ArgumentName x
from :: forall x. ArgumentName -> Rep ArgumentName x
$cto :: forall x. Rep ArgumentName x -> ArgumentName
to :: forall x. Rep ArgumentName x -> ArgumentName
Generic)

instance ToErrorValue ArgumentName where
  toErrorValue :: ArgumentName -> ErrorMessage
toErrorValue (ArgumentName Text
txt) = Text -> ErrorMessage
squote Text
txt

instance HasCodec ArgumentName where
  codec :: JSONCodec ArgumentName
codec = (Text -> ArgumentName)
-> (ArgumentName -> Text)
-> Codec Value Text Text
-> JSONCodec ArgumentName
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Text -> ArgumentName
ArgumentName ArgumentName -> Text
getArgumentName Codec Value Text Text
forall value. HasCodec value => JSONCodec value
codec

deriving newtype instance ToJSON ArgumentName

deriving newtype instance FromJSON ArgumentName

deriving newtype instance ToJSONKey ArgumentName

deriving newtype instance FromJSONKey ArgumentName

instance NFData ArgumentName