{-# 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 PromotionCodesResourceRestrictions
module StripeAPI.Types.PromotionCodesResourceRestrictions 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.promotion_codes_resource_restrictions@ in the specification.
data PromotionCodesResourceRestrictions = PromotionCodesResourceRestrictions
  { -- | first_time_transaction: A Boolean indicating if the Promotion Code should only be redeemed for Customers without any successful payments or invoices
    PromotionCodesResourceRestrictions -> Bool
promotionCodesResourceRestrictionsFirstTimeTransaction :: GHC.Types.Bool,
    -- | minimum_amount: Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be \$100 or more to work).
    PromotionCodesResourceRestrictions -> Maybe Int
promotionCodesResourceRestrictionsMinimumAmount :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | minimum_amount_currency: Three-letter [ISO code](https:\/\/stripe.com\/docs\/currencies) for minimum_amount
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    PromotionCodesResourceRestrictions -> Maybe Text
promotionCodesResourceRestrictionsMinimumAmountCurrency :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
  }
  deriving
    ( Int -> PromotionCodesResourceRestrictions -> ShowS
[PromotionCodesResourceRestrictions] -> ShowS
PromotionCodesResourceRestrictions -> String
(Int -> PromotionCodesResourceRestrictions -> ShowS)
-> (PromotionCodesResourceRestrictions -> String)
-> ([PromotionCodesResourceRestrictions] -> ShowS)
-> Show PromotionCodesResourceRestrictions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PromotionCodesResourceRestrictions] -> ShowS
$cshowList :: [PromotionCodesResourceRestrictions] -> ShowS
show :: PromotionCodesResourceRestrictions -> String
$cshow :: PromotionCodesResourceRestrictions -> String
showsPrec :: Int -> PromotionCodesResourceRestrictions -> ShowS
$cshowsPrec :: Int -> PromotionCodesResourceRestrictions -> ShowS
GHC.Show.Show,
      PromotionCodesResourceRestrictions
-> PromotionCodesResourceRestrictions -> Bool
(PromotionCodesResourceRestrictions
 -> PromotionCodesResourceRestrictions -> Bool)
-> (PromotionCodesResourceRestrictions
    -> PromotionCodesResourceRestrictions -> Bool)
-> Eq PromotionCodesResourceRestrictions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PromotionCodesResourceRestrictions
-> PromotionCodesResourceRestrictions -> Bool
$c/= :: PromotionCodesResourceRestrictions
-> PromotionCodesResourceRestrictions -> Bool
== :: PromotionCodesResourceRestrictions
-> PromotionCodesResourceRestrictions -> Bool
$c== :: PromotionCodesResourceRestrictions
-> PromotionCodesResourceRestrictions -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON PromotionCodesResourceRestrictions where
  toJSON :: PromotionCodesResourceRestrictions -> Value
toJSON PromotionCodesResourceRestrictions
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"first_time_transaction" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCodesResourceRestrictions -> Bool
promotionCodesResourceRestrictionsFirstTimeTransaction PromotionCodesResourceRestrictions
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"minimum_amount" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCodesResourceRestrictions -> Maybe Int
promotionCodesResourceRestrictionsMinimumAmount PromotionCodesResourceRestrictions
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"minimum_amount_currency" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCodesResourceRestrictions -> Maybe Text
promotionCodesResourceRestrictionsMinimumAmountCurrency PromotionCodesResourceRestrictions
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: PromotionCodesResourceRestrictions -> Encoding
toEncoding PromotionCodesResourceRestrictions
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"first_time_transaction" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCodesResourceRestrictions -> Bool
promotionCodesResourceRestrictionsFirstTimeTransaction PromotionCodesResourceRestrictions
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"minimum_amount" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCodesResourceRestrictions -> Maybe Int
promotionCodesResourceRestrictionsMinimumAmount PromotionCodesResourceRestrictions
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"minimum_amount_currency" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCodesResourceRestrictions -> Maybe Text
promotionCodesResourceRestrictionsMinimumAmountCurrency PromotionCodesResourceRestrictions
obj)))

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

-- | Create a new 'PromotionCodesResourceRestrictions' with all required fields.
mkPromotionCodesResourceRestrictions ::
  -- | 'promotionCodesResourceRestrictionsFirstTimeTransaction'
  GHC.Types.Bool ->
  PromotionCodesResourceRestrictions
mkPromotionCodesResourceRestrictions :: Bool -> PromotionCodesResourceRestrictions
mkPromotionCodesResourceRestrictions Bool
promotionCodesResourceRestrictionsFirstTimeTransaction =
  PromotionCodesResourceRestrictions :: Bool
-> Maybe Int -> Maybe Text -> PromotionCodesResourceRestrictions
PromotionCodesResourceRestrictions
    { promotionCodesResourceRestrictionsFirstTimeTransaction :: Bool
promotionCodesResourceRestrictionsFirstTimeTransaction = Bool
promotionCodesResourceRestrictionsFirstTimeTransaction,
      promotionCodesResourceRestrictionsMinimumAmount :: Maybe Int
promotionCodesResourceRestrictionsMinimumAmount = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      promotionCodesResourceRestrictionsMinimumAmountCurrency :: Maybe Text
promotionCodesResourceRestrictionsMinimumAmountCurrency = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
    }