{-# 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 Capability
module StripeAPI.Types.Capability 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 {-# SOURCE #-} StripeAPI.Types.Account
import {-# SOURCE #-} StripeAPI.Types.AccountCapabilityRequirements
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.capability@ in the specification.
--
-- This is an object representing a capability for a Stripe account.
--
-- Related guide: [Account capabilities](https:\/\/stripe.com\/docs\/connect\/account-capabilities).
data Capability = Capability
  { -- | account: The account for which the capability enables functionality.
    Capability -> CapabilityAccount'Variants
capabilityAccount :: CapabilityAccount'Variants,
    -- | id: The identifier for the capability.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Capability -> Text
capabilityId :: Data.Text.Internal.Text,
    -- | requested: Whether the capability has been requested.
    Capability -> Bool
capabilityRequested :: GHC.Types.Bool,
    -- | requested_at: Time at which the capability was requested. Measured in seconds since the Unix epoch.
    Capability -> Maybe Int
capabilityRequestedAt :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | requirements:
    Capability -> Maybe AccountCapabilityRequirements
capabilityRequirements :: (GHC.Maybe.Maybe AccountCapabilityRequirements),
    -- | status: The status of the capability. Can be \`active\`, \`inactive\`, \`pending\`, or \`unrequested\`.
    Capability -> CapabilityStatus'
capabilityStatus :: CapabilityStatus'
  }
  deriving
    ( Int -> Capability -> ShowS
[Capability] -> ShowS
Capability -> String
(Int -> Capability -> ShowS)
-> (Capability -> String)
-> ([Capability] -> ShowS)
-> Show Capability
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Capability] -> ShowS
$cshowList :: [Capability] -> ShowS
show :: Capability -> String
$cshow :: Capability -> String
showsPrec :: Int -> Capability -> ShowS
$cshowsPrec :: Int -> Capability -> ShowS
GHC.Show.Show,
      Capability -> Capability -> Bool
(Capability -> Capability -> Bool)
-> (Capability -> Capability -> Bool) -> Eq Capability
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Capability -> Capability -> Bool
$c/= :: Capability -> Capability -> Bool
== :: Capability -> Capability -> Bool
$c== :: Capability -> Capability -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON Capability where
  toJSON :: Capability -> Value
toJSON Capability
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"account" Text -> CapabilityAccount'Variants -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> CapabilityAccount'Variants
capabilityAccount Capability
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> Text
capabilityId Capability
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"requested" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> Bool
capabilityRequested Capability
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"requested_at" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> Maybe Int
capabilityRequestedAt Capability
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"requirements" Text -> Maybe AccountCapabilityRequirements -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> Maybe AccountCapabilityRequirements
capabilityRequirements Capability
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"status" Text -> CapabilityStatus' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> CapabilityStatus'
capabilityStatus Capability
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"object" Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Text -> Value
Data.Aeson.Types.Internal.String Text
"capability" Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: Capability -> Encoding
toEncoding Capability
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"account" Text -> CapabilityAccount'Variants -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> CapabilityAccount'Variants
capabilityAccount Capability
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"id" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> Text
capabilityId Capability
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"requested" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> Bool
capabilityRequested Capability
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"requested_at" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> Maybe Int
capabilityRequestedAt Capability
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"requirements" Text -> Maybe AccountCapabilityRequirements -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> Maybe AccountCapabilityRequirements
capabilityRequirements Capability
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"status" Text -> CapabilityStatus' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Capability -> CapabilityStatus'
capabilityStatus Capability
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"object" Text -> Value -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Text -> Value
Data.Aeson.Types.Internal.String Text
"capability")))))))

instance Data.Aeson.Types.FromJSON.FromJSON Capability where
  parseJSON :: Value -> Parser Capability
parseJSON = String
-> (Object -> Parser Capability) -> Value -> Parser Capability
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"Capability" (\Object
obj -> ((((((CapabilityAccount'Variants
 -> Text
 -> Bool
 -> Maybe Int
 -> Maybe AccountCapabilityRequirements
 -> CapabilityStatus'
 -> Capability)
-> Parser
     (CapabilityAccount'Variants
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe AccountCapabilityRequirements
      -> CapabilityStatus'
      -> Capability)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure CapabilityAccount'Variants
-> Text
-> Bool
-> Maybe Int
-> Maybe AccountCapabilityRequirements
-> CapabilityStatus'
-> Capability
Capability Parser
  (CapabilityAccount'Variants
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe AccountCapabilityRequirements
   -> CapabilityStatus'
   -> Capability)
-> Parser CapabilityAccount'Variants
-> Parser
     (Text
      -> Bool
      -> Maybe Int
      -> Maybe AccountCapabilityRequirements
      -> CapabilityStatus'
      -> Capability)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser CapabilityAccount'Variants
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"account")) Parser
  (Text
   -> Bool
   -> Maybe Int
   -> Maybe AccountCapabilityRequirements
   -> CapabilityStatus'
   -> Capability)
-> Parser Text
-> Parser
     (Bool
      -> Maybe Int
      -> Maybe AccountCapabilityRequirements
      -> CapabilityStatus'
      -> Capability)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"id")) Parser
  (Bool
   -> Maybe Int
   -> Maybe AccountCapabilityRequirements
   -> CapabilityStatus'
   -> Capability)
-> Parser Bool
-> Parser
     (Maybe Int
      -> Maybe AccountCapabilityRequirements
      -> CapabilityStatus'
      -> Capability)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"requested")) Parser
  (Maybe Int
   -> Maybe AccountCapabilityRequirements
   -> CapabilityStatus'
   -> Capability)
-> Parser (Maybe Int)
-> Parser
     (Maybe AccountCapabilityRequirements
      -> CapabilityStatus' -> Capability)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"requested_at")) Parser
  (Maybe AccountCapabilityRequirements
   -> CapabilityStatus' -> Capability)
-> Parser (Maybe AccountCapabilityRequirements)
-> Parser (CapabilityStatus' -> Capability)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe AccountCapabilityRequirements)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"requirements")) Parser (CapabilityStatus' -> Capability)
-> Parser CapabilityStatus' -> Parser Capability
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser CapabilityStatus'
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"status"))

-- | Create a new 'Capability' with all required fields.
mkCapability ::
  -- | 'capabilityAccount'
  CapabilityAccount'Variants ->
  -- | 'capabilityId'
  Data.Text.Internal.Text ->
  -- | 'capabilityRequested'
  GHC.Types.Bool ->
  -- | 'capabilityStatus'
  CapabilityStatus' ->
  Capability
mkCapability :: CapabilityAccount'Variants
-> Text -> Bool -> CapabilityStatus' -> Capability
mkCapability CapabilityAccount'Variants
capabilityAccount Text
capabilityId Bool
capabilityRequested CapabilityStatus'
capabilityStatus =
  Capability :: CapabilityAccount'Variants
-> Text
-> Bool
-> Maybe Int
-> Maybe AccountCapabilityRequirements
-> CapabilityStatus'
-> Capability
Capability
    { capabilityAccount :: CapabilityAccount'Variants
capabilityAccount = CapabilityAccount'Variants
capabilityAccount,
      capabilityId :: Text
capabilityId = Text
capabilityId,
      capabilityRequested :: Bool
capabilityRequested = Bool
capabilityRequested,
      capabilityRequestedAt :: Maybe Int
capabilityRequestedAt = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      capabilityRequirements :: Maybe AccountCapabilityRequirements
capabilityRequirements = Maybe AccountCapabilityRequirements
forall a. Maybe a
GHC.Maybe.Nothing,
      capabilityStatus :: CapabilityStatus'
capabilityStatus = CapabilityStatus'
capabilityStatus
    }

-- | Defines the oneOf schema located at @components.schemas.capability.properties.account.anyOf@ in the specification.
--
-- The account for which the capability enables functionality.
data CapabilityAccount'Variants
  = CapabilityAccount'Text Data.Text.Internal.Text
  | CapabilityAccount'Account Account
  deriving (Int -> CapabilityAccount'Variants -> ShowS
[CapabilityAccount'Variants] -> ShowS
CapabilityAccount'Variants -> String
(Int -> CapabilityAccount'Variants -> ShowS)
-> (CapabilityAccount'Variants -> String)
-> ([CapabilityAccount'Variants] -> ShowS)
-> Show CapabilityAccount'Variants
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CapabilityAccount'Variants] -> ShowS
$cshowList :: [CapabilityAccount'Variants] -> ShowS
show :: CapabilityAccount'Variants -> String
$cshow :: CapabilityAccount'Variants -> String
showsPrec :: Int -> CapabilityAccount'Variants -> ShowS
$cshowsPrec :: Int -> CapabilityAccount'Variants -> ShowS
GHC.Show.Show, CapabilityAccount'Variants -> CapabilityAccount'Variants -> Bool
(CapabilityAccount'Variants -> CapabilityAccount'Variants -> Bool)
-> (CapabilityAccount'Variants
    -> CapabilityAccount'Variants -> Bool)
-> Eq CapabilityAccount'Variants
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CapabilityAccount'Variants -> CapabilityAccount'Variants -> Bool
$c/= :: CapabilityAccount'Variants -> CapabilityAccount'Variants -> Bool
== :: CapabilityAccount'Variants -> CapabilityAccount'Variants -> Bool
$c== :: CapabilityAccount'Variants -> CapabilityAccount'Variants -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON CapabilityAccount'Variants where
  toJSON :: CapabilityAccount'Variants -> Value
toJSON (CapabilityAccount'Text Text
a) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
a
  toJSON (CapabilityAccount'Account Account
a) = Account -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Account
a

instance Data.Aeson.Types.FromJSON.FromJSON CapabilityAccount'Variants where
  parseJSON :: Value -> Parser CapabilityAccount'Variants
parseJSON Value
val = case (Text -> CapabilityAccount'Variants
CapabilityAccount'Text (Text -> CapabilityAccount'Variants)
-> Result Text -> Result CapabilityAccount'Variants
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> Value -> Result Text
forall a. FromJSON a => Value -> Result a
Data.Aeson.Types.FromJSON.fromJSON Value
val) Result CapabilityAccount'Variants
-> Result CapabilityAccount'Variants
-> Result CapabilityAccount'Variants
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
GHC.Base.<|> ((Account -> CapabilityAccount'Variants
CapabilityAccount'Account (Account -> CapabilityAccount'Variants)
-> Result Account -> Result CapabilityAccount'Variants
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> Value -> Result Account
forall a. FromJSON a => Value -> Result a
Data.Aeson.Types.FromJSON.fromJSON Value
val) Result CapabilityAccount'Variants
-> Result CapabilityAccount'Variants
-> Result CapabilityAccount'Variants
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
GHC.Base.<|> String -> Result CapabilityAccount'Variants
forall a. String -> Result a
Data.Aeson.Types.Internal.Error String
"No variant matched") of
    Data.Aeson.Types.Internal.Success CapabilityAccount'Variants
a -> CapabilityAccount'Variants -> Parser CapabilityAccount'Variants
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure CapabilityAccount'Variants
a
    Data.Aeson.Types.Internal.Error String
a -> String -> Parser CapabilityAccount'Variants
forall (m :: * -> *) a. MonadFail m => String -> m a
Control.Monad.Fail.fail String
a

-- | Defines the enum schema located at @components.schemas.capability.properties.status@ in the specification.
--
-- The status of the capability. Can be \`active\`, \`inactive\`, \`pending\`, or \`unrequested\`.
data CapabilityStatus'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    CapabilityStatus'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.
    CapabilityStatus'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"active"@
    CapabilityStatus'EnumActive
  | -- | Represents the JSON value @"disabled"@
    CapabilityStatus'EnumDisabled
  | -- | Represents the JSON value @"inactive"@
    CapabilityStatus'EnumInactive
  | -- | Represents the JSON value @"pending"@
    CapabilityStatus'EnumPending
  | -- | Represents the JSON value @"unrequested"@
    CapabilityStatus'EnumUnrequested
  deriving (Int -> CapabilityStatus' -> ShowS
[CapabilityStatus'] -> ShowS
CapabilityStatus' -> String
(Int -> CapabilityStatus' -> ShowS)
-> (CapabilityStatus' -> String)
-> ([CapabilityStatus'] -> ShowS)
-> Show CapabilityStatus'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CapabilityStatus'] -> ShowS
$cshowList :: [CapabilityStatus'] -> ShowS
show :: CapabilityStatus' -> String
$cshow :: CapabilityStatus' -> String
showsPrec :: Int -> CapabilityStatus' -> ShowS
$cshowsPrec :: Int -> CapabilityStatus' -> ShowS
GHC.Show.Show, CapabilityStatus' -> CapabilityStatus' -> Bool
(CapabilityStatus' -> CapabilityStatus' -> Bool)
-> (CapabilityStatus' -> CapabilityStatus' -> Bool)
-> Eq CapabilityStatus'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CapabilityStatus' -> CapabilityStatus' -> Bool
$c/= :: CapabilityStatus' -> CapabilityStatus' -> Bool
== :: CapabilityStatus' -> CapabilityStatus' -> Bool
$c== :: CapabilityStatus' -> CapabilityStatus' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON CapabilityStatus' where
  toJSON :: CapabilityStatus' -> Value
toJSON (CapabilityStatus'Other Value
val) = Value
val
  toJSON (CapabilityStatus'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (CapabilityStatus'
CapabilityStatus'EnumActive) = Value
"active"
  toJSON (CapabilityStatus'
CapabilityStatus'EnumDisabled) = Value
"disabled"
  toJSON (CapabilityStatus'
CapabilityStatus'EnumInactive) = Value
"inactive"
  toJSON (CapabilityStatus'
CapabilityStatus'EnumPending) = Value
"pending"
  toJSON (CapabilityStatus'
CapabilityStatus'EnumUnrequested) = Value
"unrequested"

instance Data.Aeson.Types.FromJSON.FromJSON CapabilityStatus' where
  parseJSON :: Value -> Parser CapabilityStatus'
parseJSON Value
val =
    CapabilityStatus' -> Parser CapabilityStatus'
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
"active" -> CapabilityStatus'
CapabilityStatus'EnumActive
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"disabled" -> CapabilityStatus'
CapabilityStatus'EnumDisabled
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"inactive" -> CapabilityStatus'
CapabilityStatus'EnumInactive
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"pending" -> CapabilityStatus'
CapabilityStatus'EnumPending
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"unrequested" -> CapabilityStatus'
CapabilityStatus'EnumUnrequested
            | Bool
GHC.Base.otherwise -> Value -> CapabilityStatus'
CapabilityStatus'Other Value
val
      )