{-# 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 CouponDiscount
module RecurlyClient.Types.CouponDiscount 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
import qualified Data.ByteString as Data.ByteString.Internal
import qualified Data.Foldable
import qualified Data.Functor
import qualified Data.Maybe
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text as 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 RecurlyClient.Common
import RecurlyClient.TypeAlias
import {-# SOURCE #-} RecurlyClient.Types.CouponDiscountPricing
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

{- | Defines the object schema located at @components.schemas.CouponDiscount@ in the specification.

Details of the discount a coupon applies. Will contain a \`type\`
property and one of the following properties: \`percent\`, \`fixed\`, \`trial\`.
-}
data CouponDiscount = CouponDiscount
    { CouponDiscount -> Maybe [CouponDiscountPricing]
couponDiscountCurrencies :: (GHC.Maybe.Maybe [CouponDiscountPricing])
    -- ^ currencies: This is only present when \`type=fixed\`.
    , CouponDiscount -> Maybe Int
couponDiscountPercent :: (GHC.Maybe.Maybe GHC.Types.Int)
    -- ^ percent: This is only present when \`type=percent\`.
    , CouponDiscount -> Maybe CouponDiscountTrial
couponDiscountTrial :: (GHC.Maybe.Maybe CouponDiscountTrial)
    -- ^ trial: This is only present when \`type=free_trial\`.
    , CouponDiscount -> Maybe CouponDiscountType
couponDiscountType :: (GHC.Maybe.Maybe CouponDiscountType)
    -- ^ type
    }
    deriving
        ( Int -> CouponDiscount -> ShowS
[CouponDiscount] -> ShowS
CouponDiscount -> String
(Int -> CouponDiscount -> ShowS)
-> (CouponDiscount -> String)
-> ([CouponDiscount] -> ShowS)
-> Show CouponDiscount
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CouponDiscount -> ShowS
showsPrec :: Int -> CouponDiscount -> ShowS
$cshow :: CouponDiscount -> String
show :: CouponDiscount -> String
$cshowList :: [CouponDiscount] -> ShowS
showList :: [CouponDiscount] -> ShowS
GHC.Show.Show
        , CouponDiscount -> CouponDiscount -> Bool
(CouponDiscount -> CouponDiscount -> Bool)
-> (CouponDiscount -> CouponDiscount -> Bool) -> Eq CouponDiscount
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CouponDiscount -> CouponDiscount -> Bool
== :: CouponDiscount -> CouponDiscount -> Bool
$c/= :: CouponDiscount -> CouponDiscount -> Bool
/= :: CouponDiscount -> CouponDiscount -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON CouponDiscount where
    toJSON :: CouponDiscount -> Value
toJSON CouponDiscount
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Pair]
-> ([CouponDiscountPricing] -> [Pair])
-> Maybe [CouponDiscountPricing]
-> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair])
-> ([CouponDiscountPricing] -> Pair)
-> [CouponDiscountPricing]
-> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"currencies" Key -> [CouponDiscountPricing] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (CouponDiscount -> Maybe [CouponDiscountPricing]
couponDiscountCurrencies CouponDiscount
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Int -> [Pair]) -> Maybe Int -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Int -> Pair) -> Int -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"percent" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (CouponDiscount -> Maybe Int
couponDiscountPercent CouponDiscount
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair]
-> (CouponDiscountTrial -> [Pair])
-> Maybe CouponDiscountTrial
-> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair])
-> (CouponDiscountTrial -> Pair) -> CouponDiscountTrial -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"trial" Key -> CouponDiscountTrial -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (CouponDiscount -> Maybe CouponDiscountTrial
couponDiscountTrial CouponDiscount
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair]
-> (CouponDiscountType -> [Pair])
-> Maybe CouponDiscountType
-> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair])
-> (CouponDiscountType -> Pair) -> CouponDiscountType -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"type" Key -> CouponDiscountType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (CouponDiscount -> Maybe CouponDiscountType
couponDiscountType CouponDiscount
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: CouponDiscount -> Encoding
toEncoding CouponDiscount
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ([Series] -> Series
forall a. Monoid a => [a] -> a
GHC.Base.mconcat ([[Series]] -> [Series]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Series]
-> ([CouponDiscountPricing] -> [Series])
-> Maybe [CouponDiscountPricing]
-> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series])
-> ([CouponDiscountPricing] -> Series)
-> [CouponDiscountPricing]
-> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"currencies" Key -> [CouponDiscountPricing] -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (CouponDiscount -> Maybe [CouponDiscountPricing]
couponDiscountCurrencies CouponDiscount
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Int -> [Series]) -> Maybe Int -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Int -> Series) -> Int -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"percent" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (CouponDiscount -> Maybe Int
couponDiscountPercent CouponDiscount
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series]
-> (CouponDiscountTrial -> [Series])
-> Maybe CouponDiscountTrial
-> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series])
-> (CouponDiscountTrial -> Series)
-> CouponDiscountTrial
-> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"trial" Key -> CouponDiscountTrial -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (CouponDiscount -> Maybe CouponDiscountTrial
couponDiscountTrial CouponDiscount
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series]
-> (CouponDiscountType -> [Series])
-> Maybe CouponDiscountType
-> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series])
-> (CouponDiscountType -> Series) -> CouponDiscountType -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"type" Key -> CouponDiscountType -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (CouponDiscount -> Maybe CouponDiscountType
couponDiscountType CouponDiscount
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON CouponDiscount where
    parseJSON :: Value -> Parser CouponDiscount
parseJSON = String
-> (Object -> Parser CouponDiscount)
-> Value
-> Parser CouponDiscount
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"CouponDiscount" (\Object
obj -> ((((Maybe [CouponDiscountPricing]
 -> Maybe Int
 -> Maybe CouponDiscountTrial
 -> Maybe CouponDiscountType
 -> CouponDiscount)
-> Parser
     (Maybe [CouponDiscountPricing]
      -> Maybe Int
      -> Maybe CouponDiscountTrial
      -> Maybe CouponDiscountType
      -> CouponDiscount)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe [CouponDiscountPricing]
-> Maybe Int
-> Maybe CouponDiscountTrial
-> Maybe CouponDiscountType
-> CouponDiscount
CouponDiscount Parser
  (Maybe [CouponDiscountPricing]
   -> Maybe Int
   -> Maybe CouponDiscountTrial
   -> Maybe CouponDiscountType
   -> CouponDiscount)
-> Parser (Maybe [CouponDiscountPricing])
-> Parser
     (Maybe Int
      -> Maybe CouponDiscountTrial
      -> Maybe CouponDiscountType
      -> CouponDiscount)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe [CouponDiscountPricing])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"currencies")) Parser
  (Maybe Int
   -> Maybe CouponDiscountTrial
   -> Maybe CouponDiscountType
   -> CouponDiscount)
-> Parser (Maybe Int)
-> Parser
     (Maybe CouponDiscountTrial
      -> Maybe CouponDiscountType -> CouponDiscount)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"percent")) Parser
  (Maybe CouponDiscountTrial
   -> Maybe CouponDiscountType -> CouponDiscount)
-> Parser (Maybe CouponDiscountTrial)
-> Parser (Maybe CouponDiscountType -> CouponDiscount)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe CouponDiscountTrial)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"trial")) Parser (Maybe CouponDiscountType -> CouponDiscount)
-> Parser (Maybe CouponDiscountType) -> Parser CouponDiscount
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe CouponDiscountType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"type"))

-- | Create a new 'CouponDiscount' with all required fields.
mkCouponDiscount :: CouponDiscount
mkCouponDiscount :: CouponDiscount
mkCouponDiscount =
    CouponDiscount
        { couponDiscountCurrencies :: Maybe [CouponDiscountPricing]
couponDiscountCurrencies = Maybe [CouponDiscountPricing]
forall a. Maybe a
GHC.Maybe.Nothing
        , couponDiscountPercent :: Maybe Int
couponDiscountPercent = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing
        , couponDiscountTrial :: Maybe CouponDiscountTrial
couponDiscountTrial = Maybe CouponDiscountTrial
forall a. Maybe a
GHC.Maybe.Nothing
        , couponDiscountType :: Maybe CouponDiscountType
couponDiscountType = Maybe CouponDiscountType
forall a. Maybe a
GHC.Maybe.Nothing
        }

{- | Defines the object schema located at @components.schemas.CouponDiscount.properties.trial@ in the specification.

This is only present when \`type=free_trial\`.
-}
data CouponDiscountTrial = CouponDiscountTrial
    { CouponDiscountTrial -> Maybe Int
couponDiscountTrialLength :: (GHC.Maybe.Maybe GHC.Types.Int)
    -- ^ length: Trial length measured in the units specified by the sibling \`unit\` property
    , CouponDiscountTrial -> Maybe CouponDiscountTrialUnit
couponDiscountTrialUnit :: (GHC.Maybe.Maybe CouponDiscountTrialUnit)
    -- ^ unit: Temporal unit of the free trial
    }
    deriving
        ( Int -> CouponDiscountTrial -> ShowS
[CouponDiscountTrial] -> ShowS
CouponDiscountTrial -> String
(Int -> CouponDiscountTrial -> ShowS)
-> (CouponDiscountTrial -> String)
-> ([CouponDiscountTrial] -> ShowS)
-> Show CouponDiscountTrial
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CouponDiscountTrial -> ShowS
showsPrec :: Int -> CouponDiscountTrial -> ShowS
$cshow :: CouponDiscountTrial -> String
show :: CouponDiscountTrial -> String
$cshowList :: [CouponDiscountTrial] -> ShowS
showList :: [CouponDiscountTrial] -> ShowS
GHC.Show.Show
        , CouponDiscountTrial -> CouponDiscountTrial -> Bool
(CouponDiscountTrial -> CouponDiscountTrial -> Bool)
-> (CouponDiscountTrial -> CouponDiscountTrial -> Bool)
-> Eq CouponDiscountTrial
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CouponDiscountTrial -> CouponDiscountTrial -> Bool
== :: CouponDiscountTrial -> CouponDiscountTrial -> Bool
$c/= :: CouponDiscountTrial -> CouponDiscountTrial -> Bool
/= :: CouponDiscountTrial -> CouponDiscountTrial -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON CouponDiscountTrial where
    toJSON :: CouponDiscountTrial -> Value
toJSON CouponDiscountTrial
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Pair] -> (Int -> [Pair]) -> Maybe Int -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Int -> Pair) -> Int -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"length" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (CouponDiscountTrial -> Maybe Int
couponDiscountTrialLength CouponDiscountTrial
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair]
-> (CouponDiscountTrialUnit -> [Pair])
-> Maybe CouponDiscountTrialUnit
-> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair])
-> (CouponDiscountTrialUnit -> Pair)
-> CouponDiscountTrialUnit
-> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"unit" Key -> CouponDiscountTrialUnit -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (CouponDiscountTrial -> Maybe CouponDiscountTrialUnit
couponDiscountTrialUnit CouponDiscountTrial
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: CouponDiscountTrial -> Encoding
toEncoding CouponDiscountTrial
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ([Series] -> Series
forall a. Monoid a => [a] -> a
GHC.Base.mconcat ([[Series]] -> [Series]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Series] -> (Int -> [Series]) -> Maybe Int -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Int -> Series) -> Int -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"length" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (CouponDiscountTrial -> Maybe Int
couponDiscountTrialLength CouponDiscountTrial
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series]
-> (CouponDiscountTrialUnit -> [Series])
-> Maybe CouponDiscountTrialUnit
-> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series])
-> (CouponDiscountTrialUnit -> Series)
-> CouponDiscountTrialUnit
-> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"unit" Key -> CouponDiscountTrialUnit -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (CouponDiscountTrial -> Maybe CouponDiscountTrialUnit
couponDiscountTrialUnit CouponDiscountTrial
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON CouponDiscountTrial where
    parseJSON :: Value -> Parser CouponDiscountTrial
parseJSON = String
-> (Object -> Parser CouponDiscountTrial)
-> Value
-> Parser CouponDiscountTrial
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"CouponDiscountTrial" (\Object
obj -> ((Maybe Int -> Maybe CouponDiscountTrialUnit -> CouponDiscountTrial)
-> Parser
     (Maybe Int -> Maybe CouponDiscountTrialUnit -> CouponDiscountTrial)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Int -> Maybe CouponDiscountTrialUnit -> CouponDiscountTrial
CouponDiscountTrial Parser
  (Maybe Int -> Maybe CouponDiscountTrialUnit -> CouponDiscountTrial)
-> Parser (Maybe Int)
-> Parser (Maybe CouponDiscountTrialUnit -> CouponDiscountTrial)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"length")) Parser (Maybe CouponDiscountTrialUnit -> CouponDiscountTrial)
-> Parser (Maybe CouponDiscountTrialUnit)
-> Parser CouponDiscountTrial
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe CouponDiscountTrialUnit)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"unit"))

-- | Create a new 'CouponDiscountTrial' with all required fields.
mkCouponDiscountTrial :: CouponDiscountTrial
mkCouponDiscountTrial :: CouponDiscountTrial
mkCouponDiscountTrial =
    CouponDiscountTrial
        { couponDiscountTrialLength :: Maybe Int
couponDiscountTrialLength = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing
        , couponDiscountTrialUnit :: Maybe CouponDiscountTrialUnit
couponDiscountTrialUnit = Maybe CouponDiscountTrialUnit
forall a. Maybe a
GHC.Maybe.Nothing
        }

{- | Defines the enum schema located at @components.schemas.CouponDiscount.properties.trial.properties.unit@ in the specification.

Temporal unit of the free trial
-}
data CouponDiscountTrialUnit
    = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
      CouponDiscountTrialUnitOther Data.Aeson.Types.Internal.Value
    | -- | This constructor can be used to send values to the server which are not present in the specification yet.
      CouponDiscountTrialUnitTyped Data.Text.Internal.Text
    | -- | Represents the JSON value @"day"@
      CouponDiscountTrialUnitEnumDay
    | -- | Represents the JSON value @"month"@
      CouponDiscountTrialUnitEnumMonth
    | -- | Represents the JSON value @"week"@
      CouponDiscountTrialUnitEnumWeek
    deriving (Int -> CouponDiscountTrialUnit -> ShowS
[CouponDiscountTrialUnit] -> ShowS
CouponDiscountTrialUnit -> String
(Int -> CouponDiscountTrialUnit -> ShowS)
-> (CouponDiscountTrialUnit -> String)
-> ([CouponDiscountTrialUnit] -> ShowS)
-> Show CouponDiscountTrialUnit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CouponDiscountTrialUnit -> ShowS
showsPrec :: Int -> CouponDiscountTrialUnit -> ShowS
$cshow :: CouponDiscountTrialUnit -> String
show :: CouponDiscountTrialUnit -> String
$cshowList :: [CouponDiscountTrialUnit] -> ShowS
showList :: [CouponDiscountTrialUnit] -> ShowS
GHC.Show.Show, CouponDiscountTrialUnit -> CouponDiscountTrialUnit -> Bool
(CouponDiscountTrialUnit -> CouponDiscountTrialUnit -> Bool)
-> (CouponDiscountTrialUnit -> CouponDiscountTrialUnit -> Bool)
-> Eq CouponDiscountTrialUnit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CouponDiscountTrialUnit -> CouponDiscountTrialUnit -> Bool
== :: CouponDiscountTrialUnit -> CouponDiscountTrialUnit -> Bool
$c/= :: CouponDiscountTrialUnit -> CouponDiscountTrialUnit -> Bool
/= :: CouponDiscountTrialUnit -> CouponDiscountTrialUnit -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON CouponDiscountTrialUnit where
    toJSON :: CouponDiscountTrialUnit -> Value
toJSON (CouponDiscountTrialUnitOther Value
val) = Value
val
    toJSON (CouponDiscountTrialUnitTyped Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
    toJSON (CouponDiscountTrialUnit
CouponDiscountTrialUnitEnumDay) = Value
"day"
    toJSON (CouponDiscountTrialUnit
CouponDiscountTrialUnitEnumMonth) = Value
"month"
    toJSON (CouponDiscountTrialUnit
CouponDiscountTrialUnitEnumWeek) = Value
"week"
instance Data.Aeson.Types.FromJSON.FromJSON CouponDiscountTrialUnit where
    parseJSON :: Value -> Parser CouponDiscountTrialUnit
parseJSON Value
val =
        CouponDiscountTrialUnit -> Parser CouponDiscountTrialUnit
forall a. a -> Parser a
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
"day" -> CouponDiscountTrialUnit
CouponDiscountTrialUnitEnumDay
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"month" -> CouponDiscountTrialUnit
CouponDiscountTrialUnitEnumMonth
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"week" -> CouponDiscountTrialUnit
CouponDiscountTrialUnitEnumWeek
                | Bool
GHC.Base.otherwise -> Value -> CouponDiscountTrialUnit
CouponDiscountTrialUnitOther Value
val
            )

-- | Defines the enum schema located at @components.schemas.CouponDiscount.properties.type@ in the specification.
data CouponDiscountType
    = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
      CouponDiscountTypeOther Data.Aeson.Types.Internal.Value
    | -- | This constructor can be used to send values to the server which are not present in the specification yet.
      CouponDiscountTypeTyped Data.Text.Internal.Text
    | -- | Represents the JSON value @"fixed"@
      CouponDiscountTypeEnumFixed
    | -- | Represents the JSON value @"free_trial"@
      CouponDiscountTypeEnumFree_trial
    | -- | Represents the JSON value @"percent"@
      CouponDiscountTypeEnumPercent
    deriving (Int -> CouponDiscountType -> ShowS
[CouponDiscountType] -> ShowS
CouponDiscountType -> String
(Int -> CouponDiscountType -> ShowS)
-> (CouponDiscountType -> String)
-> ([CouponDiscountType] -> ShowS)
-> Show CouponDiscountType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CouponDiscountType -> ShowS
showsPrec :: Int -> CouponDiscountType -> ShowS
$cshow :: CouponDiscountType -> String
show :: CouponDiscountType -> String
$cshowList :: [CouponDiscountType] -> ShowS
showList :: [CouponDiscountType] -> ShowS
GHC.Show.Show, CouponDiscountType -> CouponDiscountType -> Bool
(CouponDiscountType -> CouponDiscountType -> Bool)
-> (CouponDiscountType -> CouponDiscountType -> Bool)
-> Eq CouponDiscountType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CouponDiscountType -> CouponDiscountType -> Bool
== :: CouponDiscountType -> CouponDiscountType -> Bool
$c/= :: CouponDiscountType -> CouponDiscountType -> Bool
/= :: CouponDiscountType -> CouponDiscountType -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON CouponDiscountType where
    toJSON :: CouponDiscountType -> Value
toJSON (CouponDiscountTypeOther Value
val) = Value
val
    toJSON (CouponDiscountTypeTyped Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
    toJSON (CouponDiscountType
CouponDiscountTypeEnumFixed) = Value
"fixed"
    toJSON (CouponDiscountType
CouponDiscountTypeEnumFree_trial) = Value
"free_trial"
    toJSON (CouponDiscountType
CouponDiscountTypeEnumPercent) = Value
"percent"
instance Data.Aeson.Types.FromJSON.FromJSON CouponDiscountType where
    parseJSON :: Value -> Parser CouponDiscountType
parseJSON Value
val =
        CouponDiscountType -> Parser CouponDiscountType
forall a. a -> Parser a
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
"fixed" -> CouponDiscountType
CouponDiscountTypeEnumFixed
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"free_trial" -> CouponDiscountType
CouponDiscountTypeEnumFree_trial
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"percent" -> CouponDiscountType
CouponDiscountTypeEnumPercent
                | Bool
GHC.Base.otherwise -> Value -> CouponDiscountType
CouponDiscountTypeOther Value
val
            )