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

-- | Defines the object schema located at @components.schemas.invoice_threshold_reason@ in the specification.
data InvoiceThresholdReason = InvoiceThresholdReason
  { -- | amount_gte: The total invoice amount threshold boundary if it triggered the threshold invoice.
    InvoiceThresholdReason -> Maybe Int
invoiceThresholdReasonAmountGte :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | item_reasons: Indicates which line items triggered a threshold invoice.
    InvoiceThresholdReason -> [InvoiceItemThresholdReason]
invoiceThresholdReasonItemReasons :: ([InvoiceItemThresholdReason])
  }
  deriving
    ( Int -> InvoiceThresholdReason -> ShowS
[InvoiceThresholdReason] -> ShowS
InvoiceThresholdReason -> String
(Int -> InvoiceThresholdReason -> ShowS)
-> (InvoiceThresholdReason -> String)
-> ([InvoiceThresholdReason] -> ShowS)
-> Show InvoiceThresholdReason
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InvoiceThresholdReason] -> ShowS
$cshowList :: [InvoiceThresholdReason] -> ShowS
show :: InvoiceThresholdReason -> String
$cshow :: InvoiceThresholdReason -> String
showsPrec :: Int -> InvoiceThresholdReason -> ShowS
$cshowsPrec :: Int -> InvoiceThresholdReason -> ShowS
GHC.Show.Show,
      InvoiceThresholdReason -> InvoiceThresholdReason -> Bool
(InvoiceThresholdReason -> InvoiceThresholdReason -> Bool)
-> (InvoiceThresholdReason -> InvoiceThresholdReason -> Bool)
-> Eq InvoiceThresholdReason
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InvoiceThresholdReason -> InvoiceThresholdReason -> Bool
$c/= :: InvoiceThresholdReason -> InvoiceThresholdReason -> Bool
== :: InvoiceThresholdReason -> InvoiceThresholdReason -> Bool
$c== :: InvoiceThresholdReason -> InvoiceThresholdReason -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON InvoiceThresholdReason where
  toJSON :: InvoiceThresholdReason -> Value
toJSON InvoiceThresholdReason
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"amount_gte" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= InvoiceThresholdReason -> Maybe Int
invoiceThresholdReasonAmountGte InvoiceThresholdReason
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"item_reasons" Text -> [InvoiceItemThresholdReason] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= InvoiceThresholdReason -> [InvoiceItemThresholdReason]
invoiceThresholdReasonItemReasons InvoiceThresholdReason
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: InvoiceThresholdReason -> Encoding
toEncoding InvoiceThresholdReason
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"amount_gte" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= InvoiceThresholdReason -> Maybe Int
invoiceThresholdReasonAmountGte InvoiceThresholdReason
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"item_reasons" Text -> [InvoiceItemThresholdReason] -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= InvoiceThresholdReason -> [InvoiceItemThresholdReason]
invoiceThresholdReasonItemReasons InvoiceThresholdReason
obj))

instance Data.Aeson.Types.FromJSON.FromJSON InvoiceThresholdReason where
  parseJSON :: Value -> Parser InvoiceThresholdReason
parseJSON = String
-> (Object -> Parser InvoiceThresholdReason)
-> Value
-> Parser InvoiceThresholdReason
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"InvoiceThresholdReason" (\Object
obj -> ((Maybe Int
 -> [InvoiceItemThresholdReason] -> InvoiceThresholdReason)
-> Parser
     (Maybe Int
      -> [InvoiceItemThresholdReason] -> InvoiceThresholdReason)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Int -> [InvoiceItemThresholdReason] -> InvoiceThresholdReason
InvoiceThresholdReason Parser
  (Maybe Int
   -> [InvoiceItemThresholdReason] -> InvoiceThresholdReason)
-> Parser (Maybe Int)
-> Parser ([InvoiceItemThresholdReason] -> InvoiceThresholdReason)
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_gte")) Parser ([InvoiceItemThresholdReason] -> InvoiceThresholdReason)
-> Parser [InvoiceItemThresholdReason]
-> Parser InvoiceThresholdReason
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser [InvoiceItemThresholdReason]
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"item_reasons"))

-- | Create a new 'InvoiceThresholdReason' with all required fields.
mkInvoiceThresholdReason ::
  -- | 'invoiceThresholdReasonItemReasons'
  [InvoiceItemThresholdReason] ->
  InvoiceThresholdReason
mkInvoiceThresholdReason :: [InvoiceItemThresholdReason] -> InvoiceThresholdReason
mkInvoiceThresholdReason [InvoiceItemThresholdReason]
invoiceThresholdReasonItemReasons =
  InvoiceThresholdReason :: Maybe Int -> [InvoiceItemThresholdReason] -> InvoiceThresholdReason
InvoiceThresholdReason
    { invoiceThresholdReasonAmountGte :: Maybe Int
invoiceThresholdReasonAmountGte = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      invoiceThresholdReasonItemReasons :: [InvoiceItemThresholdReason]
invoiceThresholdReasonItemReasons = [InvoiceItemThresholdReason]
invoiceThresholdReasonItemReasons
    }