{-# 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 Fee
module StripeAPI.Types.Fee 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.fee@ in the specification.
data Fee = Fee
  { -- | amount: Amount of the fee, in cents.
    Fee -> Int
feeAmount :: GHC.Types.Int,
    -- | application: ID of the Connect application that earned the fee.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Fee -> Maybe Text
feeApplication :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | currency: Three-letter [ISO currency code](https:\/\/www.iso.org\/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https:\/\/stripe.com\/docs\/currencies).
    Fee -> Text
feeCurrency :: Data.Text.Internal.Text,
    -- | description: An arbitrary string attached to the object. Often useful for displaying to users.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Fee -> Maybe Text
feeDescription :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | type: Type of the fee, one of: \`application_fee\`, \`stripe_fee\` or \`tax\`.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Fee -> Text
feeType :: Data.Text.Internal.Text
  }
  deriving
    ( Int -> Fee -> ShowS
[Fee] -> ShowS
Fee -> String
(Int -> Fee -> ShowS)
-> (Fee -> String) -> ([Fee] -> ShowS) -> Show Fee
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Fee] -> ShowS
$cshowList :: [Fee] -> ShowS
show :: Fee -> String
$cshow :: Fee -> String
showsPrec :: Int -> Fee -> ShowS
$cshowsPrec :: Int -> Fee -> ShowS
GHC.Show.Show,
      Fee -> Fee -> Bool
(Fee -> Fee -> Bool) -> (Fee -> Fee -> Bool) -> Eq Fee
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Fee -> Fee -> Bool
$c/= :: Fee -> Fee -> Bool
== :: Fee -> Fee -> Bool
$c== :: Fee -> Fee -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON Fee where
  toJSON :: Fee -> Value
toJSON Fee
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"amount" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Int
feeAmount Fee
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"application" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Maybe Text
feeApplication Fee
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"currency" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Text
feeCurrency Fee
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"description" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Maybe Text
feeDescription Fee
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"type" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Text
feeType Fee
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: Fee -> Encoding
toEncoding Fee
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"amount" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Int
feeAmount Fee
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"application" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Maybe Text
feeApplication Fee
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"currency" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Text
feeCurrency Fee
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"description" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Maybe Text
feeDescription Fee
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"type" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Fee -> Text
feeType Fee
obj)))))

instance Data.Aeson.Types.FromJSON.FromJSON Fee where
  parseJSON :: Value -> Parser Fee
parseJSON = String -> (Object -> Parser Fee) -> Value -> Parser Fee
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"Fee" (\Object
obj -> (((((Int -> Maybe Text -> Text -> Maybe Text -> Text -> Fee)
-> Parser (Int -> Maybe Text -> Text -> Maybe Text -> Text -> Fee)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Int -> Maybe Text -> Text -> Maybe Text -> Text -> Fee
Fee Parser (Int -> Maybe Text -> Text -> Maybe Text -> Text -> Fee)
-> Parser Int
-> Parser (Maybe Text -> Text -> Maybe Text -> Text -> Fee)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"amount")) Parser (Maybe Text -> Text -> Maybe Text -> Text -> Fee)
-> Parser (Maybe Text)
-> Parser (Text -> Maybe Text -> Text -> Fee)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"application")) Parser (Text -> Maybe Text -> Text -> Fee)
-> Parser Text -> Parser (Maybe Text -> Text -> Fee)
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
"currency")) Parser (Maybe Text -> Text -> Fee)
-> Parser (Maybe Text) -> Parser (Text -> Fee)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"description")) Parser (Text -> Fee) -> Parser Text -> Parser Fee
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
"type"))

-- | Create a new 'Fee' with all required fields.
mkFee ::
  -- | 'feeAmount'
  GHC.Types.Int ->
  -- | 'feeCurrency'
  Data.Text.Internal.Text ->
  -- | 'feeType'
  Data.Text.Internal.Text ->
  Fee
mkFee :: Int -> Text -> Text -> Fee
mkFee Int
feeAmount Text
feeCurrency Text
feeType =
  Fee :: Int -> Maybe Text -> Text -> Maybe Text -> Text -> Fee
Fee
    { feeAmount :: Int
feeAmount = Int
feeAmount,
      feeApplication :: Maybe Text
feeApplication = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      feeCurrency :: Text
feeCurrency = Text
feeCurrency,
      feeDescription :: Maybe Text
feeDescription = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      feeType :: Text
feeType = Text
feeType
    }