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

-- | Defines the object schema located at @components.schemas.CouponPricing@ in the specification.
data CouponPricing = CouponPricing
    { CouponPricing -> Maybe Text
couponPricingCurrency :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
    -- ^ currency: 3-letter ISO 4217 currency code.
    , CouponPricing -> Maybe Float
couponPricingDiscount :: (GHC.Maybe.Maybe GHC.Types.Float)
    -- ^ discount: The fixed discount (in dollars) for the corresponding currency.
    }
    deriving
        ( Int -> CouponPricing -> ShowS
[CouponPricing] -> ShowS
CouponPricing -> String
(Int -> CouponPricing -> ShowS)
-> (CouponPricing -> String)
-> ([CouponPricing] -> ShowS)
-> Show CouponPricing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CouponPricing -> ShowS
showsPrec :: Int -> CouponPricing -> ShowS
$cshow :: CouponPricing -> String
show :: CouponPricing -> String
$cshowList :: [CouponPricing] -> ShowS
showList :: [CouponPricing] -> ShowS
GHC.Show.Show
        , CouponPricing -> CouponPricing -> Bool
(CouponPricing -> CouponPricing -> Bool)
-> (CouponPricing -> CouponPricing -> Bool) -> Eq CouponPricing
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CouponPricing -> CouponPricing -> Bool
== :: CouponPricing -> CouponPricing -> Bool
$c/= :: CouponPricing -> CouponPricing -> Bool
/= :: CouponPricing -> CouponPricing -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON CouponPricing where
    toJSON :: CouponPricing -> Value
toJSON CouponPricing
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Pair] -> (Text -> [Pair]) -> Maybe Text -> [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]) -> (Text -> Pair) -> Text -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"currency" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (CouponPricing -> Maybe Text
couponPricingCurrency CouponPricing
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Float -> [Pair]) -> Maybe Float -> [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]) -> (Float -> Pair) -> Float -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"discount" Key -> Float -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (CouponPricing -> Maybe Float
couponPricingDiscount CouponPricing
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: CouponPricing -> Encoding
toEncoding CouponPricing
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] -> (Text -> [Series]) -> Maybe Text -> [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]) -> (Text -> Series) -> Text -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"currency" Key -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (CouponPricing -> Maybe Text
couponPricingCurrency CouponPricing
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Float -> [Series]) -> Maybe Float -> [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]) -> (Float -> Series) -> Float -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"discount" Key -> Float -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (CouponPricing -> Maybe Float
couponPricingDiscount CouponPricing
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON CouponPricing where
    parseJSON :: Value -> Parser CouponPricing
parseJSON = String
-> (Object -> Parser CouponPricing)
-> Value
-> Parser CouponPricing
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"CouponPricing" (\Object
obj -> ((Maybe Text -> Maybe Float -> CouponPricing)
-> Parser (Maybe Text -> Maybe Float -> CouponPricing)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Text -> Maybe Float -> CouponPricing
CouponPricing Parser (Maybe Text -> Maybe Float -> CouponPricing)
-> Parser (Maybe Text) -> Parser (Maybe Float -> CouponPricing)
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 Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"currency")) Parser (Maybe Float -> CouponPricing)
-> Parser (Maybe Float) -> Parser CouponPricing
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 Float)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"discount"))

-- | Create a new 'CouponPricing' with all required fields.
mkCouponPricing :: CouponPricing
mkCouponPricing :: CouponPricing
mkCouponPricing =
    CouponPricing
        { couponPricingCurrency :: Maybe Text
couponPricingCurrency = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
        , couponPricingDiscount :: Maybe Float
couponPricingDiscount = Maybe Float
forall a. Maybe a
GHC.Maybe.Nothing
        }