{-# 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.
    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.
    accountControllerType :: (GHC.Maybe.Maybe AccountControllerType')
  }
  deriving
    ( GHC.Show.Show,
      GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON AccountController where
  toJSON obj = Data.Aeson.Types.Internal.object ("is_controller" Data.Aeson.Types.ToJSON..= accountControllerIsController obj : "type" Data.Aeson.Types.ToJSON..= accountControllerType obj : GHC.Base.mempty)
  toEncoding obj = Data.Aeson.Encoding.Internal.pairs (("is_controller" Data.Aeson.Types.ToJSON..= accountControllerIsController obj) GHC.Base.<> ("type" Data.Aeson.Types.ToJSON..= accountControllerType obj))

instance Data.Aeson.Types.FromJSON.FromJSON AccountController where
  parseJSON = Data.Aeson.Types.FromJSON.withObject "AccountController" (\obj -> (GHC.Base.pure AccountController GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "is_controller")) GHC.Base.<*> (obj Data.Aeson.Types.FromJSON..:? "type"))

-- | Create a new 'AccountController' with all required fields.
mkAccountController :: AccountController
mkAccountController =
  AccountController
    { accountControllerIsController = GHC.Maybe.Nothing,
      accountControllerType = 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 (GHC.Show.Show, GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON AccountControllerType' where
  toJSON (AccountControllerType'Other val) = val
  toJSON (AccountControllerType'Typed val) = Data.Aeson.Types.ToJSON.toJSON val
  toJSON (AccountControllerType'EnumAccount) = "account"
  toJSON (AccountControllerType'EnumApplication) = "application"

instance Data.Aeson.Types.FromJSON.FromJSON AccountControllerType' where
  parseJSON val =
    GHC.Base.pure
      ( if
            | val GHC.Classes.== "account" -> AccountControllerType'EnumAccount
            | val GHC.Classes.== "application" -> AccountControllerType'EnumApplication
            | GHC.Base.otherwise -> AccountControllerType'Other val
      )