{-# 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 AccountExternalSubscription
module RecurlyClient.Types.AccountExternalSubscription 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.AccountExternalSubscription.allOf@ in the specification.
data AccountExternalSubscription = AccountExternalSubscription
    { AccountExternalSubscription -> Text
accountExternalSubscriptionAccount_code :: Data.Text.Internal.Text
    -- ^ account_code: The account code of a new or existing account to be used when creating the external subscription.
    --
    -- Constraints:
    --
    -- * Maximum length of 50
    }
    deriving
        ( Int -> AccountExternalSubscription -> ShowS
[AccountExternalSubscription] -> ShowS
AccountExternalSubscription -> String
(Int -> AccountExternalSubscription -> ShowS)
-> (AccountExternalSubscription -> String)
-> ([AccountExternalSubscription] -> ShowS)
-> Show AccountExternalSubscription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AccountExternalSubscription -> ShowS
showsPrec :: Int -> AccountExternalSubscription -> ShowS
$cshow :: AccountExternalSubscription -> String
show :: AccountExternalSubscription -> String
$cshowList :: [AccountExternalSubscription] -> ShowS
showList :: [AccountExternalSubscription] -> ShowS
GHC.Show.Show
        , AccountExternalSubscription -> AccountExternalSubscription -> Bool
(AccountExternalSubscription
 -> AccountExternalSubscription -> Bool)
-> (AccountExternalSubscription
    -> AccountExternalSubscription -> Bool)
-> Eq AccountExternalSubscription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AccountExternalSubscription -> AccountExternalSubscription -> Bool
== :: AccountExternalSubscription -> AccountExternalSubscription -> Bool
$c/= :: AccountExternalSubscription -> AccountExternalSubscription -> Bool
/= :: AccountExternalSubscription -> AccountExternalSubscription -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON AccountExternalSubscription where
    toJSON :: AccountExternalSubscription -> Value
toJSON AccountExternalSubscription
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Key
"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..= AccountExternalSubscription -> Text
accountExternalSubscriptionAccount_code AccountExternalSubscription
obj] [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: AccountExternalSubscription -> Encoding
toEncoding AccountExternalSubscription
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
"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..= AccountExternalSubscription -> Text
accountExternalSubscriptionAccount_code AccountExternalSubscription
obj] [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON AccountExternalSubscription where
    parseJSON :: Value -> Parser AccountExternalSubscription
parseJSON = String
-> (Object -> Parser AccountExternalSubscription)
-> Value
-> Parser AccountExternalSubscription
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"AccountExternalSubscription" (\Object
obj -> (Text -> AccountExternalSubscription)
-> Parser (Text -> AccountExternalSubscription)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Text -> AccountExternalSubscription
AccountExternalSubscription Parser (Text -> AccountExternalSubscription)
-> Parser Text -> Parser AccountExternalSubscription
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
"account_code"))

-- | Create a new 'AccountExternalSubscription' with all required fields.
mkAccountExternalSubscription ::
    -- | 'accountExternalSubscriptionAccount_code'
    Data.Text.Internal.Text ->
    AccountExternalSubscription
mkAccountExternalSubscription :: Text -> AccountExternalSubscription
mkAccountExternalSubscription Text
accountExternalSubscriptionAccount_code = AccountExternalSubscription{accountExternalSubscriptionAccount_code :: Text
accountExternalSubscriptionAccount_code = Text
accountExternalSubscriptionAccount_code}