{-# 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 ChargeTransferData
module StripeAPI.Types.ChargeTransferData 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 qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.charge_transfer_data@ in the specification.
data ChargeTransferData = ChargeTransferData
  { -- | amount: The amount transferred to the destination account, if specified. By default, the entire charge amount is transferred to the destination account.
    ChargeTransferData -> Maybe Int
chargeTransferDataAmount :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | destination: ID of an existing, connected Stripe account to transfer funds to if \`transfer_data\` was specified in the charge request.
    ChargeTransferData -> ChargeTransferDataDestination'Variants
chargeTransferDataDestination :: ChargeTransferDataDestination'Variants
  }
  deriving
    ( Int -> ChargeTransferData -> ShowS
[ChargeTransferData] -> ShowS
ChargeTransferData -> String
(Int -> ChargeTransferData -> ShowS)
-> (ChargeTransferData -> String)
-> ([ChargeTransferData] -> ShowS)
-> Show ChargeTransferData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChargeTransferData] -> ShowS
$cshowList :: [ChargeTransferData] -> ShowS
show :: ChargeTransferData -> String
$cshow :: ChargeTransferData -> String
showsPrec :: Int -> ChargeTransferData -> ShowS
$cshowsPrec :: Int -> ChargeTransferData -> ShowS
GHC.Show.Show,
      ChargeTransferData -> ChargeTransferData -> Bool
(ChargeTransferData -> ChargeTransferData -> Bool)
-> (ChargeTransferData -> ChargeTransferData -> Bool)
-> Eq ChargeTransferData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChargeTransferData -> ChargeTransferData -> Bool
$c/= :: ChargeTransferData -> ChargeTransferData -> Bool
== :: ChargeTransferData -> ChargeTransferData -> Bool
$c== :: ChargeTransferData -> ChargeTransferData -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON ChargeTransferData where
  toJSON :: ChargeTransferData -> Value
toJSON ChargeTransferData
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"amount" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= ChargeTransferData -> Maybe Int
chargeTransferDataAmount ChargeTransferData
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"destination" Text -> ChargeTransferDataDestination'Variants -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= ChargeTransferData -> ChargeTransferDataDestination'Variants
chargeTransferDataDestination ChargeTransferData
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: ChargeTransferData -> Encoding
toEncoding ChargeTransferData
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"amount" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= ChargeTransferData -> Maybe Int
chargeTransferDataAmount ChargeTransferData
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"destination" Text -> ChargeTransferDataDestination'Variants -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= ChargeTransferData -> ChargeTransferDataDestination'Variants
chargeTransferDataDestination ChargeTransferData
obj))

instance Data.Aeson.Types.FromJSON.FromJSON ChargeTransferData where
  parseJSON :: Value -> Parser ChargeTransferData
parseJSON = String
-> (Object -> Parser ChargeTransferData)
-> Value
-> Parser ChargeTransferData
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"ChargeTransferData" (\Object
obj -> ((Maybe Int
 -> ChargeTransferDataDestination'Variants -> ChargeTransferData)
-> Parser
     (Maybe Int
      -> ChargeTransferDataDestination'Variants -> ChargeTransferData)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Int
-> ChargeTransferDataDestination'Variants -> ChargeTransferData
ChargeTransferData Parser
  (Maybe Int
   -> ChargeTransferDataDestination'Variants -> ChargeTransferData)
-> Parser (Maybe Int)
-> Parser
     (ChargeTransferDataDestination'Variants -> ChargeTransferData)
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
"amount")) Parser
  (ChargeTransferDataDestination'Variants -> ChargeTransferData)
-> Parser ChargeTransferDataDestination'Variants
-> Parser ChargeTransferData
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser ChargeTransferDataDestination'Variants
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"destination"))

-- | Create a new 'ChargeTransferData' with all required fields.
mkChargeTransferData ::
  -- | 'chargeTransferDataDestination'
  ChargeTransferDataDestination'Variants ->
  ChargeTransferData
mkChargeTransferData :: ChargeTransferDataDestination'Variants -> ChargeTransferData
mkChargeTransferData ChargeTransferDataDestination'Variants
chargeTransferDataDestination =
  ChargeTransferData :: Maybe Int
-> ChargeTransferDataDestination'Variants -> ChargeTransferData
ChargeTransferData
    { chargeTransferDataAmount :: Maybe Int
chargeTransferDataAmount = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      chargeTransferDataDestination :: ChargeTransferDataDestination'Variants
chargeTransferDataDestination = ChargeTransferDataDestination'Variants
chargeTransferDataDestination
    }

-- | Defines the oneOf schema located at @components.schemas.charge_transfer_data.properties.destination.anyOf@ in the specification.
--
-- ID of an existing, connected Stripe account to transfer funds to if \`transfer_data\` was specified in the charge request.
data ChargeTransferDataDestination'Variants
  = ChargeTransferDataDestination'Text Data.Text.Internal.Text
  | ChargeTransferDataDestination'Account Account
  deriving (Int -> ChargeTransferDataDestination'Variants -> ShowS
[ChargeTransferDataDestination'Variants] -> ShowS
ChargeTransferDataDestination'Variants -> String
(Int -> ChargeTransferDataDestination'Variants -> ShowS)
-> (ChargeTransferDataDestination'Variants -> String)
-> ([ChargeTransferDataDestination'Variants] -> ShowS)
-> Show ChargeTransferDataDestination'Variants
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChargeTransferDataDestination'Variants] -> ShowS
$cshowList :: [ChargeTransferDataDestination'Variants] -> ShowS
show :: ChargeTransferDataDestination'Variants -> String
$cshow :: ChargeTransferDataDestination'Variants -> String
showsPrec :: Int -> ChargeTransferDataDestination'Variants -> ShowS
$cshowsPrec :: Int -> ChargeTransferDataDestination'Variants -> ShowS
GHC.Show.Show, ChargeTransferDataDestination'Variants
-> ChargeTransferDataDestination'Variants -> Bool
(ChargeTransferDataDestination'Variants
 -> ChargeTransferDataDestination'Variants -> Bool)
-> (ChargeTransferDataDestination'Variants
    -> ChargeTransferDataDestination'Variants -> Bool)
-> Eq ChargeTransferDataDestination'Variants
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChargeTransferDataDestination'Variants
-> ChargeTransferDataDestination'Variants -> Bool
$c/= :: ChargeTransferDataDestination'Variants
-> ChargeTransferDataDestination'Variants -> Bool
== :: ChargeTransferDataDestination'Variants
-> ChargeTransferDataDestination'Variants -> Bool
$c== :: ChargeTransferDataDestination'Variants
-> ChargeTransferDataDestination'Variants -> Bool
GHC.Classes.Eq)

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

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