{-# 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 TransferData
module StripeAPI.Types.TransferData 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.transfer_data@ in the specification.
data TransferData = TransferData
  { -- | amount: Amount intended to be collected by this PaymentIntent. A positive integer representing how much to charge in the [smallest currency unit](https:\/\/stripe.com\/docs\/currencies\#zero-decimal) (e.g., 100 cents to charge \$1.00 or 100 to charge ¥100, a zero-decimal currency). The minimum amount is \$0.50 US or [equivalent in charge currency](https:\/\/stripe.com\/docs\/currencies\#minimum-and-maximum-charge-amounts). The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of \$999,999.99).
    TransferData -> Maybe Int
transferDataAmount :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | destination: The account (if any) the payment will be attributed to for tax
    -- reporting, and where funds from the payment will be transferred to upon
    -- payment success.
    TransferData -> TransferDataDestination'Variants
transferDataDestination :: TransferDataDestination'Variants
  }
  deriving
    ( Int -> TransferData -> ShowS
[TransferData] -> ShowS
TransferData -> String
(Int -> TransferData -> ShowS)
-> (TransferData -> String)
-> ([TransferData] -> ShowS)
-> Show TransferData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TransferData] -> ShowS
$cshowList :: [TransferData] -> ShowS
show :: TransferData -> String
$cshow :: TransferData -> String
showsPrec :: Int -> TransferData -> ShowS
$cshowsPrec :: Int -> TransferData -> ShowS
GHC.Show.Show,
      TransferData -> TransferData -> Bool
(TransferData -> TransferData -> Bool)
-> (TransferData -> TransferData -> Bool) -> Eq TransferData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransferData -> TransferData -> Bool
$c/= :: TransferData -> TransferData -> Bool
== :: TransferData -> TransferData -> Bool
$c== :: TransferData -> TransferData -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON TransferData where
  toJSON :: TransferData -> Value
toJSON TransferData
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..= TransferData -> Maybe Int
transferDataAmount TransferData
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"destination" Text -> TransferDataDestination'Variants -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= TransferData -> TransferDataDestination'Variants
transferDataDestination TransferData
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: TransferData -> Encoding
toEncoding TransferData
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..= TransferData -> Maybe Int
transferDataAmount TransferData
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"destination" Text -> TransferDataDestination'Variants -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= TransferData -> TransferDataDestination'Variants
transferDataDestination TransferData
obj))

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

-- | Create a new 'TransferData' with all required fields.
mkTransferData ::
  -- | 'transferDataDestination'
  TransferDataDestination'Variants ->
  TransferData
mkTransferData :: TransferDataDestination'Variants -> TransferData
mkTransferData TransferDataDestination'Variants
transferDataDestination =
  TransferData :: Maybe Int -> TransferDataDestination'Variants -> TransferData
TransferData
    { transferDataAmount :: Maybe Int
transferDataAmount = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      transferDataDestination :: TransferDataDestination'Variants
transferDataDestination = TransferDataDestination'Variants
transferDataDestination
    }

-- | Defines the oneOf schema located at @components.schemas.transfer_data.properties.destination.anyOf@ in the specification.
--
-- The account (if any) the payment will be attributed to for tax
-- reporting, and where funds from the payment will be transferred to upon
-- payment success.
data TransferDataDestination'Variants
  = TransferDataDestination'Text Data.Text.Internal.Text
  | TransferDataDestination'Account Account
  deriving (Int -> TransferDataDestination'Variants -> ShowS
[TransferDataDestination'Variants] -> ShowS
TransferDataDestination'Variants -> String
(Int -> TransferDataDestination'Variants -> ShowS)
-> (TransferDataDestination'Variants -> String)
-> ([TransferDataDestination'Variants] -> ShowS)
-> Show TransferDataDestination'Variants
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TransferDataDestination'Variants] -> ShowS
$cshowList :: [TransferDataDestination'Variants] -> ShowS
show :: TransferDataDestination'Variants -> String
$cshow :: TransferDataDestination'Variants -> String
showsPrec :: Int -> TransferDataDestination'Variants -> ShowS
$cshowsPrec :: Int -> TransferDataDestination'Variants -> ShowS
GHC.Show.Show, TransferDataDestination'Variants
-> TransferDataDestination'Variants -> Bool
(TransferDataDestination'Variants
 -> TransferDataDestination'Variants -> Bool)
-> (TransferDataDestination'Variants
    -> TransferDataDestination'Variants -> Bool)
-> Eq TransferDataDestination'Variants
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransferDataDestination'Variants
-> TransferDataDestination'Variants -> Bool
$c/= :: TransferDataDestination'Variants
-> TransferDataDestination'Variants -> Bool
== :: TransferDataDestination'Variants
-> TransferDataDestination'Variants -> Bool
$c== :: TransferDataDestination'Variants
-> TransferDataDestination'Variants -> Bool
GHC.Classes.Eq)

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

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