{-# 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 AccountController
module StripeAPI.Types.AccountController 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.Char8
import qualified Data.ByteString.Char8 as Data.ByteString.Internal
import qualified Data.Functor
import qualified Data.Scientific
import qualified Data.Text
import qualified 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 StripeAPI.Common
import StripeAPI.TypeAlias
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.account_controller@ in the specification.
data AccountController = AccountController
  { -- | is_controller: \`true\` if the Connect application retrieving the resource controls the account and can therefore exercise [platform controls](https:\/\/stripe.com\/docs\/connect\/platform-controls-for-standard-accounts). Otherwise, this field is null.
    AccountController -> Maybe Bool
accountControllerIsController :: (GHC.Maybe.Maybe GHC.Types.Bool),
    -- | type: The controller type. Can be \`application\`, if a Connect application controls the account, or \`account\`, if the account controls itself.
    AccountController -> Maybe AccountControllerType'
accountControllerType :: (GHC.Maybe.Maybe AccountControllerType')
  }
  deriving
    ( Int -> AccountController -> ShowS
[AccountController] -> ShowS
AccountController -> String
(Int -> AccountController -> ShowS)
-> (AccountController -> String)
-> ([AccountController] -> ShowS)
-> Show AccountController
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccountController] -> ShowS
$cshowList :: [AccountController] -> ShowS
show :: AccountController -> String
$cshow :: AccountController -> String
showsPrec :: Int -> AccountController -> ShowS
$cshowsPrec :: Int -> AccountController -> ShowS
GHC.Show.Show,
      AccountController -> AccountController -> Bool
(AccountController -> AccountController -> Bool)
-> (AccountController -> AccountController -> Bool)
-> Eq AccountController
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccountController -> AccountController -> Bool
$c/= :: AccountController -> AccountController -> Bool
== :: AccountController -> AccountController -> Bool
$c== :: AccountController -> AccountController -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON AccountController where
  toJSON :: AccountController -> Value
toJSON AccountController
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"is_controller" Text -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= AccountController -> Maybe Bool
accountControllerIsController AccountController
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"type" Text -> Maybe AccountControllerType' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= AccountController -> Maybe AccountControllerType'
accountControllerType AccountController
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: AccountController -> Encoding
toEncoding AccountController
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"is_controller" Text -> Maybe Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= AccountController -> Maybe Bool
accountControllerIsController AccountController
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"type" Text -> Maybe AccountControllerType' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= AccountController -> Maybe AccountControllerType'
accountControllerType AccountController
obj))

instance Data.Aeson.Types.FromJSON.FromJSON AccountController where
  parseJSON :: Value -> Parser AccountController
parseJSON = String
-> (Object -> Parser AccountController)
-> Value
-> Parser AccountController
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"AccountController" (\Object
obj -> ((Maybe Bool -> Maybe AccountControllerType' -> AccountController)
-> Parser
     (Maybe Bool -> Maybe AccountControllerType' -> AccountController)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Bool -> Maybe AccountControllerType' -> AccountController
AccountController Parser
  (Maybe Bool -> Maybe AccountControllerType' -> AccountController)
-> Parser (Maybe Bool)
-> Parser (Maybe AccountControllerType' -> AccountController)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"is_controller")) Parser (Maybe AccountControllerType' -> AccountController)
-> Parser (Maybe AccountControllerType')
-> Parser AccountController
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe AccountControllerType')
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"type"))

-- | Create a new 'AccountController' with all required fields.
mkAccountController :: AccountController
mkAccountController :: AccountController
mkAccountController =
  AccountController :: Maybe Bool -> Maybe AccountControllerType' -> AccountController
AccountController
    { accountControllerIsController :: Maybe Bool
accountControllerIsController = Maybe Bool
forall a. Maybe a
GHC.Maybe.Nothing,
      accountControllerType :: Maybe AccountControllerType'
accountControllerType = Maybe AccountControllerType'
forall a. Maybe a
GHC.Maybe.Nothing
    }

-- | Defines the enum schema located at @components.schemas.account_controller.properties.type@ in the specification.
--
-- The controller type. Can be \`application\`, if a Connect application controls the account, or \`account\`, if the account controls itself.
data AccountControllerType'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    AccountControllerType'Other Data.Aeson.Types.Internal.Value
  | -- | This constructor can be used to send values to the server which are not present in the specification yet.
    AccountControllerType'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"account"@
    AccountControllerType'EnumAccount
  | -- | Represents the JSON value @"application"@
    AccountControllerType'EnumApplication
  deriving (Int -> AccountControllerType' -> ShowS
[AccountControllerType'] -> ShowS
AccountControllerType' -> String
(Int -> AccountControllerType' -> ShowS)
-> (AccountControllerType' -> String)
-> ([AccountControllerType'] -> ShowS)
-> Show AccountControllerType'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccountControllerType'] -> ShowS
$cshowList :: [AccountControllerType'] -> ShowS
show :: AccountControllerType' -> String
$cshow :: AccountControllerType' -> String
showsPrec :: Int -> AccountControllerType' -> ShowS
$cshowsPrec :: Int -> AccountControllerType' -> ShowS
GHC.Show.Show, AccountControllerType' -> AccountControllerType' -> Bool
(AccountControllerType' -> AccountControllerType' -> Bool)
-> (AccountControllerType' -> AccountControllerType' -> Bool)
-> Eq AccountControllerType'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccountControllerType' -> AccountControllerType' -> Bool
$c/= :: AccountControllerType' -> AccountControllerType' -> Bool
== :: AccountControllerType' -> AccountControllerType' -> Bool
$c== :: AccountControllerType' -> AccountControllerType' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON AccountControllerType' where
  toJSON :: AccountControllerType' -> Value
toJSON (AccountControllerType'Other Value
val) = Value
val
  toJSON (AccountControllerType'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (AccountControllerType'
AccountControllerType'EnumAccount) = Value
"account"
  toJSON (AccountControllerType'
AccountControllerType'EnumApplication) = Value
"application"

instance Data.Aeson.Types.FromJSON.FromJSON AccountControllerType' where
  parseJSON :: Value -> Parser AccountControllerType'
parseJSON Value
val =
    AccountControllerType' -> Parser AccountControllerType'
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
"account" -> AccountControllerType'
AccountControllerType'EnumAccount
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"application" -> AccountControllerType'
AccountControllerType'EnumApplication
            | Bool
GHC.Base.otherwise -> Value -> AccountControllerType'
AccountControllerType'Other Value
val
      )