{-# LANGUAGE MultiWayIf #-}
-- CHANGE WITH CAUTION: This is a generated code file generated by https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator.
{-# LANGUAGE OverloadedStrings #-}

-- | Contains the types generated from the schema ExternalAccountCreate
module RecurlyClient.Types.ExternalAccountCreate where

import qualified Control.Monad.Fail
import qualified Data.Aeson
import qualified Data.Aeson as Data.Aeson.Encoding.Internal
import qualified Data.Aeson as Data.Aeson.Types
import qualified Data.Aeson as Data.Aeson.Types.FromJSON
import qualified Data.Aeson as Data.Aeson.Types.Internal
import qualified Data.Aeson as Data.Aeson.Types.ToJSON
import qualified Data.ByteString
import qualified Data.ByteString as Data.ByteString.Internal
import qualified Data.Foldable
import qualified Data.Functor
import qualified Data.Maybe
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text as Data.Text.Internal
import qualified Data.Time.Calendar as Data.Time.Calendar.Days
import qualified Data.Time.LocalTime as Data.Time.LocalTime.Internal.ZonedTime
import qualified GHC.Base
import qualified GHC.Classes
import qualified GHC.Int
import qualified GHC.Show
import qualified GHC.Types
import qualified RecurlyClient.Common
import RecurlyClient.TypeAlias
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.ExternalAccountCreate@ in the specification.
data ExternalAccountCreate = ExternalAccountCreate
    { ExternalAccountCreate -> Text
externalAccountCreateExternal_account_code :: Data.Text.Internal.Text
    -- ^ external_account_code: Represents the account code for the external account.
    , ExternalAccountCreate -> Text
externalAccountCreateExternal_connection_type :: Data.Text.Internal.Text
    -- ^ external_connection_type: Represents the connection type. One of the connection types of your enabled App Connectors
    }
    deriving
        ( Int -> ExternalAccountCreate -> ShowS
[ExternalAccountCreate] -> ShowS
ExternalAccountCreate -> String
(Int -> ExternalAccountCreate -> ShowS)
-> (ExternalAccountCreate -> String)
-> ([ExternalAccountCreate] -> ShowS)
-> Show ExternalAccountCreate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExternalAccountCreate -> ShowS
showsPrec :: Int -> ExternalAccountCreate -> ShowS
$cshow :: ExternalAccountCreate -> String
show :: ExternalAccountCreate -> String
$cshowList :: [ExternalAccountCreate] -> ShowS
showList :: [ExternalAccountCreate] -> ShowS
GHC.Show.Show
        , ExternalAccountCreate -> ExternalAccountCreate -> Bool
(ExternalAccountCreate -> ExternalAccountCreate -> Bool)
-> (ExternalAccountCreate -> ExternalAccountCreate -> Bool)
-> Eq ExternalAccountCreate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExternalAccountCreate -> ExternalAccountCreate -> Bool
== :: ExternalAccountCreate -> ExternalAccountCreate -> Bool
$c/= :: ExternalAccountCreate -> ExternalAccountCreate -> Bool
/= :: ExternalAccountCreate -> ExternalAccountCreate -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON ExternalAccountCreate where
    toJSON :: ExternalAccountCreate -> Value
toJSON ExternalAccountCreate
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Key
"external_account_code" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..= ExternalAccountCreate -> Text
externalAccountCreateExternal_account_code ExternalAccountCreate
obj] [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Key
"external_connection_type" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..= ExternalAccountCreate -> Text
externalAccountCreateExternal_connection_type ExternalAccountCreate
obj] [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: ExternalAccountCreate -> Encoding
toEncoding ExternalAccountCreate
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ([Series] -> Series
forall a. Monoid a => [a] -> a
GHC.Base.mconcat ([[Series]] -> [Series]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Key
"external_account_code" Key -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..= ExternalAccountCreate -> Text
externalAccountCreateExternal_account_code ExternalAccountCreate
obj] [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Key
"external_connection_type" Key -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..= ExternalAccountCreate -> Text
externalAccountCreateExternal_connection_type ExternalAccountCreate
obj] [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON ExternalAccountCreate where
    parseJSON :: Value -> Parser ExternalAccountCreate
parseJSON = String
-> (Object -> Parser ExternalAccountCreate)
-> Value
-> Parser ExternalAccountCreate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"ExternalAccountCreate" (\Object
obj -> ((Text -> Text -> ExternalAccountCreate)
-> Parser (Text -> Text -> ExternalAccountCreate)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Text -> Text -> ExternalAccountCreate
ExternalAccountCreate Parser (Text -> Text -> ExternalAccountCreate)
-> Parser Text -> Parser (Text -> ExternalAccountCreate)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
Data.Aeson.Types.FromJSON..: Key
"external_account_code")) Parser (Text -> ExternalAccountCreate)
-> Parser Text -> Parser ExternalAccountCreate
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
Data.Aeson.Types.FromJSON..: Key
"external_connection_type"))

-- | Create a new 'ExternalAccountCreate' with all required fields.
mkExternalAccountCreate ::
    -- | 'externalAccountCreateExternal_account_code'
    Data.Text.Internal.Text ->
    -- | 'externalAccountCreateExternal_connection_type'
    Data.Text.Internal.Text ->
    ExternalAccountCreate
mkExternalAccountCreate :: Text -> Text -> ExternalAccountCreate
mkExternalAccountCreate Text
externalAccountCreateExternal_account_code Text
externalAccountCreateExternal_connection_type =
    ExternalAccountCreate
        { externalAccountCreateExternal_account_code :: Text
externalAccountCreateExternal_account_code = Text
externalAccountCreateExternal_account_code
        , externalAccountCreateExternal_connection_type :: Text
externalAccountCreateExternal_connection_type = Text
externalAccountCreateExternal_connection_type
        }