{-# 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 GeneralLedgerAccountCreate
module RecurlyClient.Types.GeneralLedgerAccountCreate 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.GeneralLedgerAccountCreate@ in the specification.

Create a new liability or revenue general ledger account.
-}
data GeneralLedgerAccountCreate = GeneralLedgerAccountCreate
    { GeneralLedgerAccountCreate
-> Maybe GeneralLedgerAccountCreateAccount_type
generalLedgerAccountCreateAccount_type :: (GHC.Maybe.Maybe GeneralLedgerAccountCreateAccount_type)
    -- ^ account_type
    , GeneralLedgerAccountCreate -> Maybe Text
generalLedgerAccountCreateCode :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
    -- ^ code: Unique code to identify the ledger account. Each code must start
    -- with a letter or number. The following special characters are
    -- allowed: \`-_.,:\`
    --
    --
    -- Constraints:
    --
    -- * Maximum length of 255
    -- * Must match pattern \'\/^[A-Za-z0-9](( *)?[\\-A-Za-z0-9_.,:])*\$\/\'
    , GeneralLedgerAccountCreate -> Maybe Text
generalLedgerAccountCreateDescription :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
    -- ^ description: Optional description.
    --
    -- Constraints:
    --
    -- * Maximum length of 255
    }
    deriving
        ( Int -> GeneralLedgerAccountCreate -> ShowS
[GeneralLedgerAccountCreate] -> ShowS
GeneralLedgerAccountCreate -> String
(Int -> GeneralLedgerAccountCreate -> ShowS)
-> (GeneralLedgerAccountCreate -> String)
-> ([GeneralLedgerAccountCreate] -> ShowS)
-> Show GeneralLedgerAccountCreate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeneralLedgerAccountCreate -> ShowS
showsPrec :: Int -> GeneralLedgerAccountCreate -> ShowS
$cshow :: GeneralLedgerAccountCreate -> String
show :: GeneralLedgerAccountCreate -> String
$cshowList :: [GeneralLedgerAccountCreate] -> ShowS
showList :: [GeneralLedgerAccountCreate] -> ShowS
GHC.Show.Show
        , GeneralLedgerAccountCreate -> GeneralLedgerAccountCreate -> Bool
(GeneralLedgerAccountCreate -> GeneralLedgerAccountCreate -> Bool)
-> (GeneralLedgerAccountCreate
    -> GeneralLedgerAccountCreate -> Bool)
-> Eq GeneralLedgerAccountCreate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeneralLedgerAccountCreate -> GeneralLedgerAccountCreate -> Bool
== :: GeneralLedgerAccountCreate -> GeneralLedgerAccountCreate -> Bool
$c/= :: GeneralLedgerAccountCreate -> GeneralLedgerAccountCreate -> Bool
/= :: GeneralLedgerAccountCreate -> GeneralLedgerAccountCreate -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON GeneralLedgerAccountCreate where
    toJSON :: GeneralLedgerAccountCreate -> Value
toJSON GeneralLedgerAccountCreate
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Pair]
-> (GeneralLedgerAccountCreateAccount_type -> [Pair])
-> Maybe GeneralLedgerAccountCreateAccount_type
-> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair])
-> (GeneralLedgerAccountCreateAccount_type -> Pair)
-> GeneralLedgerAccountCreateAccount_type
-> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"account_type" Key -> GeneralLedgerAccountCreateAccount_type -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (GeneralLedgerAccountCreate
-> Maybe GeneralLedgerAccountCreateAccount_type
generalLedgerAccountCreateAccount_type GeneralLedgerAccountCreate
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Text -> Pair) -> Text -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"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..=)) (GeneralLedgerAccountCreate -> Maybe Text
generalLedgerAccountCreateCode GeneralLedgerAccountCreate
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Text -> Pair) -> Text -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"description" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (GeneralLedgerAccountCreate -> Maybe Text
generalLedgerAccountCreateDescription GeneralLedgerAccountCreate
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: GeneralLedgerAccountCreate -> Encoding
toEncoding GeneralLedgerAccountCreate
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 ([Series]
-> (GeneralLedgerAccountCreateAccount_type -> [Series])
-> Maybe GeneralLedgerAccountCreateAccount_type
-> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series])
-> (GeneralLedgerAccountCreateAccount_type -> Series)
-> GeneralLedgerAccountCreateAccount_type
-> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"account_type" Key -> GeneralLedgerAccountCreateAccount_type -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (GeneralLedgerAccountCreate
-> Maybe GeneralLedgerAccountCreateAccount_type
generalLedgerAccountCreateAccount_type GeneralLedgerAccountCreate
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Text -> [Series]) -> Maybe Text -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Text -> Series) -> Text -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"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..=)) (GeneralLedgerAccountCreate -> Maybe Text
generalLedgerAccountCreateCode GeneralLedgerAccountCreate
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Text -> [Series]) -> Maybe Text -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Text -> Series) -> Text -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"description" Key -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (GeneralLedgerAccountCreate -> Maybe Text
generalLedgerAccountCreateDescription GeneralLedgerAccountCreate
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON GeneralLedgerAccountCreate where
    parseJSON :: Value -> Parser GeneralLedgerAccountCreate
parseJSON = String
-> (Object -> Parser GeneralLedgerAccountCreate)
-> Value
-> Parser GeneralLedgerAccountCreate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"GeneralLedgerAccountCreate" (\Object
obj -> (((Maybe GeneralLedgerAccountCreateAccount_type
 -> Maybe Text -> Maybe Text -> GeneralLedgerAccountCreate)
-> Parser
     (Maybe GeneralLedgerAccountCreateAccount_type
      -> Maybe Text -> Maybe Text -> GeneralLedgerAccountCreate)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe GeneralLedgerAccountCreateAccount_type
-> Maybe Text -> Maybe Text -> GeneralLedgerAccountCreate
GeneralLedgerAccountCreate Parser
  (Maybe GeneralLedgerAccountCreateAccount_type
   -> Maybe Text -> Maybe Text -> GeneralLedgerAccountCreate)
-> Parser (Maybe GeneralLedgerAccountCreateAccount_type)
-> Parser (Maybe Text -> Maybe Text -> GeneralLedgerAccountCreate)
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 (Maybe GeneralLedgerAccountCreateAccount_type)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"account_type")) Parser (Maybe Text -> Maybe Text -> GeneralLedgerAccountCreate)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> GeneralLedgerAccountCreate)
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 (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"code")) Parser (Maybe Text -> GeneralLedgerAccountCreate)
-> Parser (Maybe Text) -> Parser GeneralLedgerAccountCreate
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 (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"description"))

-- | Create a new 'GeneralLedgerAccountCreate' with all required fields.
mkGeneralLedgerAccountCreate :: GeneralLedgerAccountCreate
mkGeneralLedgerAccountCreate :: GeneralLedgerAccountCreate
mkGeneralLedgerAccountCreate =
    GeneralLedgerAccountCreate
        { generalLedgerAccountCreateAccount_type :: Maybe GeneralLedgerAccountCreateAccount_type
generalLedgerAccountCreateAccount_type = Maybe GeneralLedgerAccountCreateAccount_type
forall a. Maybe a
GHC.Maybe.Nothing
        , generalLedgerAccountCreateCode :: Maybe Text
generalLedgerAccountCreateCode = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
        , generalLedgerAccountCreateDescription :: Maybe Text
generalLedgerAccountCreateDescription = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
        }

-- | Defines the enum schema located at @components.schemas.GeneralLedgerAccountCreate.properties.account_type@ in the specification.
data GeneralLedgerAccountCreateAccount_type
    = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
      GeneralLedgerAccountCreateAccount_typeOther Data.Aeson.Types.Internal.Value
    | -- | This constructor can be used to send values to the server which are not present in the specification yet.
      GeneralLedgerAccountCreateAccount_typeTyped Data.Text.Internal.Text
    | -- | Represents the JSON value @"liability"@
      GeneralLedgerAccountCreateAccount_typeEnumLiability
    | -- | Represents the JSON value @"revenue"@
      GeneralLedgerAccountCreateAccount_typeEnumRevenue
    deriving (Int -> GeneralLedgerAccountCreateAccount_type -> ShowS
[GeneralLedgerAccountCreateAccount_type] -> ShowS
GeneralLedgerAccountCreateAccount_type -> String
(Int -> GeneralLedgerAccountCreateAccount_type -> ShowS)
-> (GeneralLedgerAccountCreateAccount_type -> String)
-> ([GeneralLedgerAccountCreateAccount_type] -> ShowS)
-> Show GeneralLedgerAccountCreateAccount_type
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GeneralLedgerAccountCreateAccount_type -> ShowS
showsPrec :: Int -> GeneralLedgerAccountCreateAccount_type -> ShowS
$cshow :: GeneralLedgerAccountCreateAccount_type -> String
show :: GeneralLedgerAccountCreateAccount_type -> String
$cshowList :: [GeneralLedgerAccountCreateAccount_type] -> ShowS
showList :: [GeneralLedgerAccountCreateAccount_type] -> ShowS
GHC.Show.Show, GeneralLedgerAccountCreateAccount_type
-> GeneralLedgerAccountCreateAccount_type -> Bool
(GeneralLedgerAccountCreateAccount_type
 -> GeneralLedgerAccountCreateAccount_type -> Bool)
-> (GeneralLedgerAccountCreateAccount_type
    -> GeneralLedgerAccountCreateAccount_type -> Bool)
-> Eq GeneralLedgerAccountCreateAccount_type
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GeneralLedgerAccountCreateAccount_type
-> GeneralLedgerAccountCreateAccount_type -> Bool
== :: GeneralLedgerAccountCreateAccount_type
-> GeneralLedgerAccountCreateAccount_type -> Bool
$c/= :: GeneralLedgerAccountCreateAccount_type
-> GeneralLedgerAccountCreateAccount_type -> Bool
/= :: GeneralLedgerAccountCreateAccount_type
-> GeneralLedgerAccountCreateAccount_type -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON GeneralLedgerAccountCreateAccount_type where
    toJSON :: GeneralLedgerAccountCreateAccount_type -> Value
toJSON (GeneralLedgerAccountCreateAccount_typeOther Value
val) = Value
val
    toJSON (GeneralLedgerAccountCreateAccount_typeTyped Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
    toJSON (GeneralLedgerAccountCreateAccount_type
GeneralLedgerAccountCreateAccount_typeEnumLiability) = Value
"liability"
    toJSON (GeneralLedgerAccountCreateAccount_type
GeneralLedgerAccountCreateAccount_typeEnumRevenue) = Value
"revenue"
instance Data.Aeson.Types.FromJSON.FromJSON GeneralLedgerAccountCreateAccount_type where
    parseJSON :: Value -> Parser GeneralLedgerAccountCreateAccount_type
parseJSON Value
val =
        GeneralLedgerAccountCreateAccount_type
-> Parser GeneralLedgerAccountCreateAccount_type
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure
            ( if
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"liability" -> GeneralLedgerAccountCreateAccount_type
GeneralLedgerAccountCreateAccount_typeEnumLiability
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"revenue" -> GeneralLedgerAccountCreateAccount_type
GeneralLedgerAccountCreateAccount_typeEnumRevenue
                | Bool
GHC.Base.otherwise -> Value -> GeneralLedgerAccountCreateAccount_type
GeneralLedgerAccountCreateAccount_typeOther Value
val
            )