{-# 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 AddOnPricing
module RecurlyClient.Types.AddOnPricing 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.AddOnPricing@ in the specification.
data AddOnPricing = AddOnPricing
    { AddOnPricing -> Text
addOnPricingCurrency :: Data.Text.Internal.Text
    -- ^ currency: 3-letter ISO 4217 currency code.
    --
    -- Constraints:
    --
    -- * Maximum length of 3
    , AddOnPricing -> Maybe Bool
addOnPricingTax_inclusive :: (GHC.Maybe.Maybe GHC.Types.Bool)
    -- ^ tax_inclusive: This field is deprecated. Please do not use it.
    , AddOnPricing -> Maybe Float
addOnPricingUnit_amount :: (GHC.Maybe.Maybe GHC.Types.Float)
    -- ^ unit_amount: Allows up to 2 decimal places. Required unless \`unit_amount_decimal\` is provided.
    --
    -- Constraints:
    --
    -- * Maxium  of 1000000.0
    -- * Minimum  of 0.0
    , AddOnPricing -> Maybe Text
addOnPricingUnit_amount_decimal :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
    -- ^ unit_amount_decimal: Allows up to 9 decimal places. Only supported when \`add_on_type\` = \`usage\`.
    -- If \`unit_amount_decimal\` is provided, \`unit_amount\` cannot be provided.
    --
    --
    -- Constraints:
    --
    -- * Maxium  of 1000000.0
    -- * Minimum  of 0.0
    }
    deriving
        ( Int -> AddOnPricing -> ShowS
[AddOnPricing] -> ShowS
AddOnPricing -> String
(Int -> AddOnPricing -> ShowS)
-> (AddOnPricing -> String)
-> ([AddOnPricing] -> ShowS)
-> Show AddOnPricing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AddOnPricing -> ShowS
showsPrec :: Int -> AddOnPricing -> ShowS
$cshow :: AddOnPricing -> String
show :: AddOnPricing -> String
$cshowList :: [AddOnPricing] -> ShowS
showList :: [AddOnPricing] -> ShowS
GHC.Show.Show
        , AddOnPricing -> AddOnPricing -> Bool
(AddOnPricing -> AddOnPricing -> Bool)
-> (AddOnPricing -> AddOnPricing -> Bool) -> Eq AddOnPricing
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AddOnPricing -> AddOnPricing -> Bool
== :: AddOnPricing -> AddOnPricing -> Bool
$c/= :: AddOnPricing -> AddOnPricing -> Bool
/= :: AddOnPricing -> AddOnPricing -> Bool
GHC.Classes.Eq
        )

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

-- | Create a new 'AddOnPricing' with all required fields.
mkAddOnPricing ::
    -- | 'addOnPricingCurrency'
    Data.Text.Internal.Text ->
    AddOnPricing
mkAddOnPricing :: Text -> AddOnPricing
mkAddOnPricing Text
addOnPricingCurrency =
    AddOnPricing
        { addOnPricingCurrency :: Text
addOnPricingCurrency = Text
addOnPricingCurrency
        , addOnPricingTax_inclusive :: Maybe Bool
addOnPricingTax_inclusive = Maybe Bool
forall a. Maybe a
GHC.Maybe.Nothing
        , addOnPricingUnit_amount :: Maybe Float
addOnPricingUnit_amount = Maybe Float
forall a. Maybe a
GHC.Maybe.Nothing
        , addOnPricingUnit_amount_decimal :: Maybe Text
addOnPricingUnit_amount_decimal = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
        }