{-# 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 InvoiceItemThresholdReason
module StripeAPI.Types.InvoiceItemThresholdReason 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.invoice_item_threshold_reason@ in the specification.
data InvoiceItemThresholdReason = InvoiceItemThresholdReason
  { -- | line_item_ids: The IDs of the line items that triggered the threshold invoice.
    InvoiceItemThresholdReason -> [Text]
invoiceItemThresholdReasonLineItemIds :: ([Data.Text.Internal.Text]),
    -- | usage_gte: The quantity threshold boundary that applied to the given line item.
    InvoiceItemThresholdReason -> Int
invoiceItemThresholdReasonUsageGte :: GHC.Types.Int
  }
  deriving
    ( Int -> InvoiceItemThresholdReason -> ShowS
[InvoiceItemThresholdReason] -> ShowS
InvoiceItemThresholdReason -> String
(Int -> InvoiceItemThresholdReason -> ShowS)
-> (InvoiceItemThresholdReason -> String)
-> ([InvoiceItemThresholdReason] -> ShowS)
-> Show InvoiceItemThresholdReason
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InvoiceItemThresholdReason] -> ShowS
$cshowList :: [InvoiceItemThresholdReason] -> ShowS
show :: InvoiceItemThresholdReason -> String
$cshow :: InvoiceItemThresholdReason -> String
showsPrec :: Int -> InvoiceItemThresholdReason -> ShowS
$cshowsPrec :: Int -> InvoiceItemThresholdReason -> ShowS
GHC.Show.Show,
      InvoiceItemThresholdReason -> InvoiceItemThresholdReason -> Bool
(InvoiceItemThresholdReason -> InvoiceItemThresholdReason -> Bool)
-> (InvoiceItemThresholdReason
    -> InvoiceItemThresholdReason -> Bool)
-> Eq InvoiceItemThresholdReason
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InvoiceItemThresholdReason -> InvoiceItemThresholdReason -> Bool
$c/= :: InvoiceItemThresholdReason -> InvoiceItemThresholdReason -> Bool
== :: InvoiceItemThresholdReason -> InvoiceItemThresholdReason -> Bool
$c== :: InvoiceItemThresholdReason -> InvoiceItemThresholdReason -> Bool
GHC.Classes.Eq
    )

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

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

-- | Create a new 'InvoiceItemThresholdReason' with all required fields.
mkInvoiceItemThresholdReason ::
  -- | 'invoiceItemThresholdReasonLineItemIds'
  [Data.Text.Internal.Text] ->
  -- | 'invoiceItemThresholdReasonUsageGte'
  GHC.Types.Int ->
  InvoiceItemThresholdReason
mkInvoiceItemThresholdReason :: [Text] -> Int -> InvoiceItemThresholdReason
mkInvoiceItemThresholdReason [Text]
invoiceItemThresholdReasonLineItemIds Int
invoiceItemThresholdReasonUsageGte =
  InvoiceItemThresholdReason :: [Text] -> Int -> InvoiceItemThresholdReason
InvoiceItemThresholdReason
    { invoiceItemThresholdReasonLineItemIds :: [Text]
invoiceItemThresholdReasonLineItemIds = [Text]
invoiceItemThresholdReasonLineItemIds,
      invoiceItemThresholdReasonUsageGte :: Int
invoiceItemThresholdReasonUsageGte = Int
invoiceItemThresholdReasonUsageGte
    }