module Hasura.RQL.Types.EECredentials
  ( EEClientCredentials (..),
    EEClientId (..),
  )
where

import Data.Aeson (FromJSON, (.:))
import Data.Aeson qualified as J
import Hasura.Prelude

data EEClientCredentials = EEClientCredentials
  { EEClientCredentials -> EEClientId
eccClientId :: EEClientId,
    EEClientCredentials -> Text
eccClientSecret :: Text
  }

newtype EEClientId = EEClientId {EEClientId -> Text
_getEEClientId :: Text}
  deriving newtype (Value -> Parser [EEClientId]
Value -> Parser EEClientId
(Value -> Parser EEClientId)
-> (Value -> Parser [EEClientId]) -> FromJSON EEClientId
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser EEClientId
parseJSON :: Value -> Parser EEClientId
$cparseJSONList :: Value -> Parser [EEClientId]
parseJSONList :: Value -> Parser [EEClientId]
FromJSON)

instance FromJSON EEClientCredentials where
  parseJSON :: Value -> Parser EEClientCredentials
parseJSON = String
-> (Object -> Parser EEClientCredentials)
-> Value
-> Parser EEClientCredentials
forall a. String -> (Object -> Parser a) -> Value -> Parser a
J.withObject String
"EEClientCredentials" ((Object -> Parser EEClientCredentials)
 -> Value -> Parser EEClientCredentials)
-> (Object -> Parser EEClientCredentials)
-> Value
-> Parser EEClientCredentials
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    EEClientId
eccClientId <- Object
o Object -> Key -> Parser EEClientId
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"client_id"
    Text
eccClientSecret <- Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"client_secret"
    EEClientCredentials -> Parser EEClientCredentials
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure EEClientCredentials {Text
EEClientId
eccClientId :: EEClientId
eccClientSecret :: Text
eccClientId :: EEClientId
eccClientSecret :: Text
..}