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

-- | Defines the object schema located at @components.schemas.coupon@ in the specification.
--
-- 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).
data Coupon = Coupon
  { -- | amount_off: Amount (in the \`currency\` specified) that will be taken off the subtotal of any invoices for this customer.
    Coupon -> Maybe Int
couponAmountOff :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | applies_to:
    Coupon -> Maybe CouponAppliesTo
couponAppliesTo :: (GHC.Maybe.Maybe CouponAppliesTo),
    -- | created: Time at which the object was created. Measured in seconds since the Unix epoch.
    Coupon -> Int
couponCreated :: GHC.Types.Int,
    -- | currency: If \`amount_off\` has been set, the three-letter [ISO code for the currency](https:\/\/stripe.com\/docs\/currencies) of the amount to take off.
    Coupon -> Maybe Text
couponCurrency :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | duration: One of \`forever\`, \`once\`, and \`repeating\`. Describes how long a customer who applies this coupon will get the discount.
    Coupon -> CouponDuration'
couponDuration :: CouponDuration',
    -- | duration_in_months: If \`duration\` is \`repeating\`, the number of months the coupon applies. Null if coupon \`duration\` is \`forever\` or \`once\`.
    Coupon -> Maybe Int
couponDurationInMonths :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | id: Unique identifier for the object.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Coupon -> Text
couponId :: 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.
    Coupon -> Bool
couponLivemode :: GHC.Types.Bool,
    -- | max_redemptions: Maximum number of times this coupon can be redeemed, in total, across all customers, before it is no longer valid.
    Coupon -> Maybe Int
couponMaxRedemptions :: (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.
    Coupon -> Maybe Object
couponMetadata :: (GHC.Maybe.Maybe Data.Aeson.Types.Internal.Object),
    -- | name: Name of the coupon displayed to customers on for instance invoices or receipts.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    Coupon -> Maybe Text
couponName :: (GHC.Maybe.Maybe Data.Text.Internal.Text),
    -- | percent_off: Percent that will be taken off the subtotal of any invoices for this customer for the duration of the coupon. For example, a coupon with percent_off of 50 will make a %s100 invoice %s50 instead.
    Coupon -> Maybe Double
couponPercentOff :: (GHC.Maybe.Maybe GHC.Types.Double),
    -- | redeem_by: Date after which the coupon can no longer be redeemed.
    Coupon -> Maybe Int
couponRedeemBy :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | times_redeemed: Number of times this coupon has been applied to a customer.
    Coupon -> Int
couponTimesRedeemed :: GHC.Types.Int,
    -- | valid: Taking account of the above properties, whether this coupon can still be applied to a customer.
    Coupon -> Bool
couponValid :: GHC.Types.Bool
  }
  deriving
    ( Int -> Coupon -> ShowS
[Coupon] -> ShowS
Coupon -> String
(Int -> Coupon -> ShowS)
-> (Coupon -> String) -> ([Coupon] -> ShowS) -> Show Coupon
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Coupon] -> ShowS
$cshowList :: [Coupon] -> ShowS
show :: Coupon -> String
$cshow :: Coupon -> String
showsPrec :: Int -> Coupon -> ShowS
$cshowsPrec :: Int -> Coupon -> ShowS
GHC.Show.Show,
      Coupon -> Coupon -> Bool
(Coupon -> Coupon -> Bool)
-> (Coupon -> Coupon -> Bool) -> Eq Coupon
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Coupon -> Coupon -> Bool
$c/= :: Coupon -> Coupon -> Bool
== :: Coupon -> Coupon -> Bool
$c== :: Coupon -> Coupon -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON Coupon where
  toJSON :: Coupon -> Value
toJSON Coupon
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"amount_off" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Int
couponAmountOff Coupon
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"applies_to" Text -> Maybe CouponAppliesTo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe CouponAppliesTo
couponAppliesTo Coupon
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..= Coupon -> Int
couponCreated Coupon
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"currency" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Text
couponCurrency Coupon
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"duration" Text -> CouponDuration' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> CouponDuration'
couponDuration Coupon
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"duration_in_months" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Int
couponDurationInMonths Coupon
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..= Coupon -> Text
couponId Coupon
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..= Coupon -> Bool
couponLivemode Coupon
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..= Coupon -> Maybe Int
couponMaxRedemptions Coupon
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..= Coupon -> Maybe Object
couponMetadata Coupon
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"name" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Text
couponName Coupon
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"percent_off" Text -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Double
couponPercentOff Coupon
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"redeem_by" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Int
couponRedeemBy Coupon
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..= Coupon -> Int
couponTimesRedeemed Coupon
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"valid" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Bool
couponValid Coupon
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
"coupon" Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: Coupon -> Encoding
toEncoding Coupon
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"amount_off" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Int
couponAmountOff Coupon
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"applies_to" Text -> Maybe CouponAppliesTo -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe CouponAppliesTo
couponAppliesTo Coupon
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..= Coupon -> Int
couponCreated Coupon
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"currency" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Text
couponCurrency Coupon
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"duration" Text -> CouponDuration' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> CouponDuration'
couponDuration Coupon
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"duration_in_months" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Int
couponDurationInMonths Coupon
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..= Coupon -> Text
couponId Coupon
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..= Coupon -> Bool
couponLivemode Coupon
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..= Coupon -> Maybe Int
couponMaxRedemptions Coupon
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..= Coupon -> Maybe Object
couponMetadata Coupon
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"name" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Text
couponName Coupon
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"percent_off" Text -> Maybe Double -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Double
couponPercentOff Coupon
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"redeem_by" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Maybe Int
couponRedeemBy Coupon
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..= Coupon -> Int
couponTimesRedeemed Coupon
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"valid" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Coupon -> Bool
couponValid Coupon
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
"coupon"))))))))))))))))

instance Data.Aeson.Types.FromJSON.FromJSON Coupon where
  parseJSON :: Value -> Parser Coupon
parseJSON = String -> (Object -> Parser Coupon) -> Value -> Parser Coupon
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"Coupon" (\Object
obj -> (((((((((((((((Maybe Int
 -> Maybe CouponAppliesTo
 -> Int
 -> Maybe Text
 -> CouponDuration'
 -> Maybe Int
 -> Text
 -> Bool
 -> Maybe Int
 -> Maybe Object
 -> Maybe Text
 -> Maybe Double
 -> Maybe Int
 -> Int
 -> Bool
 -> Coupon)
-> Parser
     (Maybe Int
      -> Maybe CouponAppliesTo
      -> Int
      -> Maybe Text
      -> CouponDuration'
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Int
-> Maybe CouponAppliesTo
-> Int
-> Maybe Text
-> CouponDuration'
-> Maybe Int
-> Text
-> Bool
-> Maybe Int
-> Maybe Object
-> Maybe Text
-> Maybe Double
-> Maybe Int
-> Int
-> Bool
-> Coupon
Coupon Parser
  (Maybe Int
   -> Maybe CouponAppliesTo
   -> Int
   -> Maybe Text
   -> CouponDuration'
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser (Maybe Int)
-> Parser
     (Maybe CouponAppliesTo
      -> Int
      -> Maybe Text
      -> CouponDuration'
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
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_off")) Parser
  (Maybe CouponAppliesTo
   -> Int
   -> Maybe Text
   -> CouponDuration'
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser (Maybe CouponAppliesTo)
-> Parser
     (Int
      -> Maybe Text
      -> CouponDuration'
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe CouponAppliesTo)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"applies_to")) Parser
  (Int
   -> Maybe Text
   -> CouponDuration'
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser Int
-> Parser
     (Maybe Text
      -> CouponDuration'
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
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 Text
   -> CouponDuration'
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser (Maybe Text)
-> Parser
     (CouponDuration'
      -> Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
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
"currency")) Parser
  (CouponDuration'
   -> Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser CouponDuration'
-> Parser
     (Maybe Int
      -> Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser CouponDuration'
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"duration")) Parser
  (Maybe Int
   -> Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser (Maybe Int)
-> Parser
     (Text
      -> Bool
      -> Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
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
"duration_in_months")) Parser
  (Text
   -> Bool
   -> Maybe Int
   -> Maybe Object
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser Text
-> Parser
     (Bool
      -> Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
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
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser Bool
-> Parser
     (Maybe Int
      -> Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
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
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser (Maybe Int)
-> Parser
     (Maybe Object
      -> Maybe Text
      -> Maybe Double
      -> Maybe Int
      -> Int
      -> Bool
      -> Coupon)
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
   -> Maybe Text
   -> Maybe Double
   -> Maybe Int
   -> Int
   -> Bool
   -> Coupon)
-> Parser (Maybe Object)
-> Parser
     (Maybe Text -> Maybe Double -> Maybe Int -> Int -> Bool -> Coupon)
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
  (Maybe Text -> Maybe Double -> Maybe Int -> Int -> Bool -> Coupon)
-> Parser (Maybe Text)
-> Parser (Maybe Double -> Maybe Int -> Int -> Bool -> Coupon)
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
"name")) Parser (Maybe Double -> Maybe Int -> Int -> Bool -> Coupon)
-> Parser (Maybe Double)
-> Parser (Maybe Int -> Int -> Bool -> Coupon)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"percent_off")) Parser (Maybe Int -> Int -> Bool -> Coupon)
-> Parser (Maybe Int) -> Parser (Int -> Bool -> Coupon)
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
"redeem_by")) Parser (Int -> Bool -> Coupon)
-> Parser Int -> Parser (Bool -> Coupon)
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")) Parser (Bool -> Coupon) -> Parser Bool -> Parser Coupon
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
"valid"))

-- | Create a new 'Coupon' with all required fields.
mkCoupon ::
  -- | 'couponCreated'
  GHC.Types.Int ->
  -- | 'couponDuration'
  CouponDuration' ->
  -- | 'couponId'
  Data.Text.Internal.Text ->
  -- | 'couponLivemode'
  GHC.Types.Bool ->
  -- | 'couponTimesRedeemed'
  GHC.Types.Int ->
  -- | 'couponValid'
  GHC.Types.Bool ->
  Coupon
mkCoupon :: Int -> CouponDuration' -> Text -> Bool -> Int -> Bool -> Coupon
mkCoupon Int
couponCreated CouponDuration'
couponDuration Text
couponId Bool
couponLivemode Int
couponTimesRedeemed Bool
couponValid =
  Coupon :: Maybe Int
-> Maybe CouponAppliesTo
-> Int
-> Maybe Text
-> CouponDuration'
-> Maybe Int
-> Text
-> Bool
-> Maybe Int
-> Maybe Object
-> Maybe Text
-> Maybe Double
-> Maybe Int
-> Int
-> Bool
-> Coupon
Coupon
    { couponAmountOff :: Maybe Int
couponAmountOff = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      couponAppliesTo :: Maybe CouponAppliesTo
couponAppliesTo = Maybe CouponAppliesTo
forall a. Maybe a
GHC.Maybe.Nothing,
      couponCreated :: Int
couponCreated = Int
couponCreated,
      couponCurrency :: Maybe Text
couponCurrency = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      couponDuration :: CouponDuration'
couponDuration = CouponDuration'
couponDuration,
      couponDurationInMonths :: Maybe Int
couponDurationInMonths = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      couponId :: Text
couponId = Text
couponId,
      couponLivemode :: Bool
couponLivemode = Bool
couponLivemode,
      couponMaxRedemptions :: Maybe Int
couponMaxRedemptions = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      couponMetadata :: Maybe Object
couponMetadata = Maybe Object
forall a. Maybe a
GHC.Maybe.Nothing,
      couponName :: Maybe Text
couponName = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing,
      couponPercentOff :: Maybe Double
couponPercentOff = Maybe Double
forall a. Maybe a
GHC.Maybe.Nothing,
      couponRedeemBy :: Maybe Int
couponRedeemBy = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      couponTimesRedeemed :: Int
couponTimesRedeemed = Int
couponTimesRedeemed,
      couponValid :: Bool
couponValid = Bool
couponValid
    }

-- | Defines the enum schema located at @components.schemas.coupon.properties.duration@ in the specification.
--
-- One of \`forever\`, \`once\`, and \`repeating\`. Describes how long a customer who applies this coupon will get the discount.
data CouponDuration'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    CouponDuration'Other Data.Aeson.Types.Internal.Value
  | -- | This constructor can be used to send values to the server which are not present in the specification yet.
    CouponDuration'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"forever"@
    CouponDuration'EnumForever
  | -- | Represents the JSON value @"once"@
    CouponDuration'EnumOnce
  | -- | Represents the JSON value @"repeating"@
    CouponDuration'EnumRepeating
  deriving (Int -> CouponDuration' -> ShowS
[CouponDuration'] -> ShowS
CouponDuration' -> String
(Int -> CouponDuration' -> ShowS)
-> (CouponDuration' -> String)
-> ([CouponDuration'] -> ShowS)
-> Show CouponDuration'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CouponDuration'] -> ShowS
$cshowList :: [CouponDuration'] -> ShowS
show :: CouponDuration' -> String
$cshow :: CouponDuration' -> String
showsPrec :: Int -> CouponDuration' -> ShowS
$cshowsPrec :: Int -> CouponDuration' -> ShowS
GHC.Show.Show, CouponDuration' -> CouponDuration' -> Bool
(CouponDuration' -> CouponDuration' -> Bool)
-> (CouponDuration' -> CouponDuration' -> Bool)
-> Eq CouponDuration'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CouponDuration' -> CouponDuration' -> Bool
$c/= :: CouponDuration' -> CouponDuration' -> Bool
== :: CouponDuration' -> CouponDuration' -> Bool
$c== :: CouponDuration' -> CouponDuration' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON CouponDuration' where
  toJSON :: CouponDuration' -> Value
toJSON (CouponDuration'Other Value
val) = Value
val
  toJSON (CouponDuration'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (CouponDuration'
CouponDuration'EnumForever) = Value
"forever"
  toJSON (CouponDuration'
CouponDuration'EnumOnce) = Value
"once"
  toJSON (CouponDuration'
CouponDuration'EnumRepeating) = Value
"repeating"

instance Data.Aeson.Types.FromJSON.FromJSON CouponDuration' where
  parseJSON :: Value -> Parser CouponDuration'
parseJSON Value
val =
    CouponDuration' -> Parser CouponDuration'
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure
      ( if
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"forever" -> CouponDuration'
CouponDuration'EnumForever
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"once" -> CouponDuration'
CouponDuration'EnumOnce
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"repeating" -> CouponDuration'
CouponDuration'EnumRepeating
            | Bool
GHC.Base.otherwise -> Value -> CouponDuration'
CouponDuration'Other Value
val
      )