{-# 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 PromotionCode
module StripeAPI.Types.PromotionCode 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.Coupon
import {-# SOURCE #-} StripeAPI.Types.Customer
import {-# SOURCE #-} StripeAPI.Types.DeletedCustomer
import {-# SOURCE #-} StripeAPI.Types.PromotionCodesResourceRestrictions
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.promotion_code@ in the specification.
--
-- A Promotion Code represents a customer-redeemable code for a coupon. It can be used to
-- create multiple codes for a single coupon.
data PromotionCode = PromotionCode
  { -- | active: Whether the promotion code is currently active. A promotion code is only active if the coupon is also valid.
    PromotionCode -> Bool
promotionCodeActive :: GHC.Types.Bool,
    -- | code: The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for each customer.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    PromotionCode -> Text
promotionCodeCode :: Data.Text.Internal.Text,
    -- | coupon: A coupon contains information about a percent-off or amount-off discount you
    -- might want to apply to a customer. Coupons may be applied to [invoices](https:\/\/stripe.com\/docs\/api\#invoices) or
    -- [orders](https:\/\/stripe.com\/docs\/api\#create_order-coupon). Coupons do not work with conventional one-off [charges](https:\/\/stripe.com\/docs\/api\#create_charge).
    PromotionCode -> Coupon
promotionCodeCoupon :: Coupon,
    -- | created: Time at which the object was created. Measured in seconds since the Unix epoch.
    PromotionCode -> Int
promotionCodeCreated :: GHC.Types.Int,
    -- | customer: The customer that this promotion code can be used by.
    PromotionCode -> Maybe PromotionCodeCustomer'Variants
promotionCodeCustomer :: (GHC.Maybe.Maybe PromotionCodeCustomer'Variants),
    -- | expires_at: Date at which the promotion code can no longer be redeemed.
    PromotionCode -> Maybe Int
promotionCodeExpiresAt :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | id: Unique identifier for the object.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    PromotionCode -> Text
promotionCodeId :: Data.Text.Internal.Text,
    -- | livemode: Has the value \`true\` if the object exists in live mode or the value \`false\` if the object exists in test mode.
    PromotionCode -> Bool
promotionCodeLivemode :: GHC.Types.Bool,
    -- | max_redemptions: Maximum number of times this promotion code can be redeemed.
    PromotionCode -> Maybe Int
promotionCodeMaxRedemptions :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | metadata: Set of [key-value pairs](https:\/\/stripe.com\/docs\/api\/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
    PromotionCode -> Maybe Object
promotionCodeMetadata :: (GHC.Maybe.Maybe Data.Aeson.Types.Internal.Object),
    -- | restrictions:
    PromotionCode -> PromotionCodesResourceRestrictions
promotionCodeRestrictions :: PromotionCodesResourceRestrictions,
    -- | times_redeemed: Number of times this promotion code has been used.
    PromotionCode -> Int
promotionCodeTimesRedeemed :: GHC.Types.Int
  }
  deriving
    ( Int -> PromotionCode -> ShowS
[PromotionCode] -> ShowS
PromotionCode -> String
(Int -> PromotionCode -> ShowS)
-> (PromotionCode -> String)
-> ([PromotionCode] -> ShowS)
-> Show PromotionCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PromotionCode] -> ShowS
$cshowList :: [PromotionCode] -> ShowS
show :: PromotionCode -> String
$cshow :: PromotionCode -> String
showsPrec :: Int -> PromotionCode -> ShowS
$cshowsPrec :: Int -> PromotionCode -> ShowS
GHC.Show.Show,
      PromotionCode -> PromotionCode -> Bool
(PromotionCode -> PromotionCode -> Bool)
-> (PromotionCode -> PromotionCode -> Bool) -> Eq PromotionCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PromotionCode -> PromotionCode -> Bool
$c/= :: PromotionCode -> PromotionCode -> Bool
== :: PromotionCode -> PromotionCode -> Bool
$c== :: PromotionCode -> PromotionCode -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON PromotionCode where
  toJSON :: PromotionCode -> Value
toJSON PromotionCode
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"active" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Bool
promotionCodeActive PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"code" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Text
promotionCodeCode PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"coupon" Text -> Coupon -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Coupon
promotionCodeCoupon PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"created" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Int
promotionCodeCreated PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"customer" Text -> Maybe PromotionCodeCustomer'Variants -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Maybe PromotionCodeCustomer'Variants
promotionCodeCustomer PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"expires_at" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Maybe Int
promotionCodeExpiresAt PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Text
promotionCodeId PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"livemode" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Bool
promotionCodeLivemode PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"max_redemptions" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Maybe Int
promotionCodeMaxRedemptions PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"metadata" Text -> Maybe Object -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Maybe Object
promotionCodeMetadata PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"restrictions" Text -> PromotionCodesResourceRestrictions -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> PromotionCodesResourceRestrictions
promotionCodeRestrictions PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"times_redeemed" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Int
promotionCodeTimesRedeemed PromotionCode
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"object" Text -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Text -> Value
Data.Aeson.Types.Internal.String Text
"promotion_code" Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: PromotionCode -> Encoding
toEncoding PromotionCode
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"active" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Bool
promotionCodeActive PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"code" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Text
promotionCodeCode PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"coupon" Text -> Coupon -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Coupon
promotionCodeCoupon PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"created" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Int
promotionCodeCreated PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"customer" Text -> Maybe PromotionCodeCustomer'Variants -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Maybe PromotionCodeCustomer'Variants
promotionCodeCustomer PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"expires_at" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Maybe Int
promotionCodeExpiresAt PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"id" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Text
promotionCodeId PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"livemode" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Bool
promotionCodeLivemode PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"max_redemptions" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Maybe Int
promotionCodeMaxRedemptions PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"metadata" Text -> Maybe Object -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Maybe Object
promotionCodeMetadata PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"restrictions" Text -> PromotionCodesResourceRestrictions -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> PromotionCodesResourceRestrictions
promotionCodeRestrictions PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"times_redeemed" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PromotionCode -> Int
promotionCodeTimesRedeemed PromotionCode
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"object" Text -> Value -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Text -> Value
Data.Aeson.Types.Internal.String Text
"promotion_code")))))))))))))

instance Data.Aeson.Types.FromJSON.FromJSON PromotionCode where
  parseJSON :: Value -> Parser PromotionCode
parseJSON = String
-> (Object -> Parser PromotionCode)
-> Value
-> Parser PromotionCode
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"PromotionCode" (\Object
obj -> ((((((((((((Bool
 -> Text
 -> Coupon
 -> Int
 -> Maybe PromotionCodeCustomer'Variants
 -> Maybe Int
 -> Text
 -> Bool
 -> Maybe Int
 -> Maybe Object
 -> PromotionCodesResourceRestrictions
 -> Int
 -> PromotionCode)
-> Parser
     (Bool
      -> Text
      -> Coupon
      -> Int
      -> Maybe PromotionCodeCustomer'Variants
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Bool
-> Text
-> Coupon
-> Int
-> Maybe PromotionCodeCustomer'Variants
-> Maybe Int
-> Text
-> Bool
-> Maybe Int
-> Maybe Object
-> PromotionCodesResourceRestrictions
-> Int
-> PromotionCode
PromotionCode Parser
  (Bool
   -> Text
   -> Coupon
   -> Int
   -> Maybe PromotionCodeCustomer'Variants
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser Bool
-> Parser
     (Text
      -> Coupon
      -> Int
      -> Maybe PromotionCodeCustomer'Variants
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
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
"active")) Parser
  (Text
   -> Coupon
   -> Int
   -> Maybe PromotionCodeCustomer'Variants
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser Text
-> Parser
     (Coupon
      -> Int
      -> Maybe PromotionCodeCustomer'Variants
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
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
"code")) Parser
  (Coupon
   -> Int
   -> Maybe PromotionCodeCustomer'Variants
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser Coupon
-> Parser
     (Int
      -> Maybe PromotionCodeCustomer'Variants
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Coupon
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"coupon")) Parser
  (Int
   -> Maybe PromotionCodeCustomer'Variants
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser Int
-> Parser
     (Maybe PromotionCodeCustomer'Variants
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
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
"created")) Parser
  (Maybe PromotionCodeCustomer'Variants
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser (Maybe PromotionCodeCustomer'Variants)
-> Parser
     (Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe PromotionCodeCustomer'Variants)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"customer")) Parser
  (Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser (Maybe Int)
-> Parser
     (Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
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
"expires_at")) Parser
  (Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser Text
-> Parser
     (Bool
      -> Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
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
"id")) Parser
  (Bool
   -> Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser Bool
-> Parser
     (Maybe Int
      -> Maybe Object
      -> PromotionCodesResourceRestrictions
      -> Int
      -> PromotionCode)
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
"livemode")) Parser
  (Maybe Int
   -> Maybe Object
   -> PromotionCodesResourceRestrictions
   -> Int
   -> PromotionCode)
-> Parser (Maybe Int)
-> Parser
     (Maybe Object
      -> PromotionCodesResourceRestrictions -> Int -> PromotionCode)
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
"max_redemptions")) Parser
  (Maybe Object
   -> PromotionCodesResourceRestrictions -> Int -> PromotionCode)
-> Parser (Maybe Object)
-> Parser
     (PromotionCodesResourceRestrictions -> Int -> PromotionCode)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Object)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"metadata")) Parser (PromotionCodesResourceRestrictions -> Int -> PromotionCode)
-> Parser PromotionCodesResourceRestrictions
-> Parser (Int -> PromotionCode)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser PromotionCodesResourceRestrictions
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"restrictions")) Parser (Int -> PromotionCode) -> Parser Int -> Parser PromotionCode
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
"times_redeemed"))

-- | Create a new 'PromotionCode' with all required fields.
mkPromotionCode ::
  -- | 'promotionCodeActive'
  GHC.Types.Bool ->
  -- | 'promotionCodeCode'
  Data.Text.Internal.Text ->
  -- | 'promotionCodeCoupon'
  Coupon ->
  -- | 'promotionCodeCreated'
  GHC.Types.Int ->
  -- | 'promotionCodeId'
  Data.Text.Internal.Text ->
  -- | 'promotionCodeLivemode'
  GHC.Types.Bool ->
  -- | 'promotionCodeRestrictions'
  PromotionCodesResourceRestrictions ->
  -- | 'promotionCodeTimesRedeemed'
  GHC.Types.Int ->
  PromotionCode
mkPromotionCode :: Bool
-> Text
-> Coupon
-> Int
-> Text
-> Bool
-> PromotionCodesResourceRestrictions
-> Int
-> PromotionCode
mkPromotionCode Bool
promotionCodeActive Text
promotionCodeCode Coupon
promotionCodeCoupon Int
promotionCodeCreated Text
promotionCodeId Bool
promotionCodeLivemode PromotionCodesResourceRestrictions
promotionCodeRestrictions Int
promotionCodeTimesRedeemed =
  PromotionCode :: Bool
-> Text
-> Coupon
-> Int
-> Maybe PromotionCodeCustomer'Variants
-> Maybe Int
-> Text
-> Bool
-> Maybe Int
-> Maybe Object
-> PromotionCodesResourceRestrictions
-> Int
-> PromotionCode
PromotionCode
    { promotionCodeActive :: Bool
promotionCodeActive = Bool
promotionCodeActive,
      promotionCodeCode :: Text
promotionCodeCode = Text
promotionCodeCode,
      promotionCodeCoupon :: Coupon
promotionCodeCoupon = Coupon
promotionCodeCoupon,
      promotionCodeCreated :: Int
promotionCodeCreated = Int
promotionCodeCreated,
      promotionCodeCustomer :: Maybe PromotionCodeCustomer'Variants
promotionCodeCustomer = Maybe PromotionCodeCustomer'Variants
forall a. Maybe a
GHC.Maybe.Nothing,
      promotionCodeExpiresAt :: Maybe Int
promotionCodeExpiresAt = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      promotionCodeId :: Text
promotionCodeId = Text
promotionCodeId,
      promotionCodeLivemode :: Bool
promotionCodeLivemode = Bool
promotionCodeLivemode,
      promotionCodeMaxRedemptions :: Maybe Int
promotionCodeMaxRedemptions = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      promotionCodeMetadata :: Maybe Object
promotionCodeMetadata = Maybe Object
forall a. Maybe a
GHC.Maybe.Nothing,
      promotionCodeRestrictions :: PromotionCodesResourceRestrictions
promotionCodeRestrictions = PromotionCodesResourceRestrictions
promotionCodeRestrictions,
      promotionCodeTimesRedeemed :: Int
promotionCodeTimesRedeemed = Int
promotionCodeTimesRedeemed
    }

-- | Defines the oneOf schema located at @components.schemas.promotion_code.properties.customer.anyOf@ in the specification.
--
-- The customer that this promotion code can be used by.
data PromotionCodeCustomer'Variants
  = PromotionCodeCustomer'Text Data.Text.Internal.Text
  | PromotionCodeCustomer'Customer Customer
  | PromotionCodeCustomer'DeletedCustomer DeletedCustomer
  deriving (Int -> PromotionCodeCustomer'Variants -> ShowS
[PromotionCodeCustomer'Variants] -> ShowS
PromotionCodeCustomer'Variants -> String
(Int -> PromotionCodeCustomer'Variants -> ShowS)
-> (PromotionCodeCustomer'Variants -> String)
-> ([PromotionCodeCustomer'Variants] -> ShowS)
-> Show PromotionCodeCustomer'Variants
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PromotionCodeCustomer'Variants] -> ShowS
$cshowList :: [PromotionCodeCustomer'Variants] -> ShowS
show :: PromotionCodeCustomer'Variants -> String
$cshow :: PromotionCodeCustomer'Variants -> String
showsPrec :: Int -> PromotionCodeCustomer'Variants -> ShowS
$cshowsPrec :: Int -> PromotionCodeCustomer'Variants -> ShowS
GHC.Show.Show, PromotionCodeCustomer'Variants
-> PromotionCodeCustomer'Variants -> Bool
(PromotionCodeCustomer'Variants
 -> PromotionCodeCustomer'Variants -> Bool)
-> (PromotionCodeCustomer'Variants
    -> PromotionCodeCustomer'Variants -> Bool)
-> Eq PromotionCodeCustomer'Variants
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PromotionCodeCustomer'Variants
-> PromotionCodeCustomer'Variants -> Bool
$c/= :: PromotionCodeCustomer'Variants
-> PromotionCodeCustomer'Variants -> Bool
== :: PromotionCodeCustomer'Variants
-> PromotionCodeCustomer'Variants -> Bool
$c== :: PromotionCodeCustomer'Variants
-> PromotionCodeCustomer'Variants -> Bool
GHC.Classes.Eq)

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

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