{-# 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 ProrationSettings
module RecurlyClient.Types.ProrationSettings 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.ProrationSettings@ in the specification.

Allows you to control how any resulting charges and credits will be calculated and prorated.
-}
data ProrationSettings = ProrationSettings
    { ProrationSettings -> Maybe ProrationSettingsCharge
prorationSettingsCharge :: (GHC.Maybe.Maybe ProrationSettingsCharge)
    -- ^ charge: Determines how the amount charged is determined for this change
    , ProrationSettings -> Maybe ProrationSettingsCredit
prorationSettingsCredit :: (GHC.Maybe.Maybe ProrationSettingsCredit)
    -- ^ credit: Determines how the amount credited is determined for this change
    }
    deriving
        ( Int -> ProrationSettings -> ShowS
[ProrationSettings] -> ShowS
ProrationSettings -> String
(Int -> ProrationSettings -> ShowS)
-> (ProrationSettings -> String)
-> ([ProrationSettings] -> ShowS)
-> Show ProrationSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProrationSettings -> ShowS
showsPrec :: Int -> ProrationSettings -> ShowS
$cshow :: ProrationSettings -> String
show :: ProrationSettings -> String
$cshowList :: [ProrationSettings] -> ShowS
showList :: [ProrationSettings] -> ShowS
GHC.Show.Show
        , ProrationSettings -> ProrationSettings -> Bool
(ProrationSettings -> ProrationSettings -> Bool)
-> (ProrationSettings -> ProrationSettings -> Bool)
-> Eq ProrationSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProrationSettings -> ProrationSettings -> Bool
== :: ProrationSettings -> ProrationSettings -> Bool
$c/= :: ProrationSettings -> ProrationSettings -> Bool
/= :: ProrationSettings -> ProrationSettings -> Bool
GHC.Classes.Eq
        )

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

-- | Create a new 'ProrationSettings' with all required fields.
mkProrationSettings :: ProrationSettings
mkProrationSettings :: ProrationSettings
mkProrationSettings =
    ProrationSettings
        { prorationSettingsCharge :: Maybe ProrationSettingsCharge
prorationSettingsCharge = Maybe ProrationSettingsCharge
forall a. Maybe a
GHC.Maybe.Nothing
        , prorationSettingsCredit :: Maybe ProrationSettingsCredit
prorationSettingsCredit = Maybe ProrationSettingsCredit
forall a. Maybe a
GHC.Maybe.Nothing
        }

{- | Defines the enum schema located at @components.schemas.ProrationSettings.properties.charge@ in the specification.

Determines how the amount charged is determined for this change
-}
data ProrationSettingsCharge
    = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
      ProrationSettingsChargeOther Data.Aeson.Types.Internal.Value
    | -- | This constructor can be used to send values to the server which are not present in the specification yet.
      ProrationSettingsChargeTyped Data.Text.Internal.Text
    | -- | Represents the JSON value @"full_amount"@
      ProrationSettingsChargeEnumFull_amount
    | -- | Represents the JSON value @"prorated_amount"@
      ProrationSettingsChargeEnumProrated_amount
    | -- | Represents the JSON value @"none"@
      ProrationSettingsChargeEnumNone
    deriving (Int -> ProrationSettingsCharge -> ShowS
[ProrationSettingsCharge] -> ShowS
ProrationSettingsCharge -> String
(Int -> ProrationSettingsCharge -> ShowS)
-> (ProrationSettingsCharge -> String)
-> ([ProrationSettingsCharge] -> ShowS)
-> Show ProrationSettingsCharge
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProrationSettingsCharge -> ShowS
showsPrec :: Int -> ProrationSettingsCharge -> ShowS
$cshow :: ProrationSettingsCharge -> String
show :: ProrationSettingsCharge -> String
$cshowList :: [ProrationSettingsCharge] -> ShowS
showList :: [ProrationSettingsCharge] -> ShowS
GHC.Show.Show, ProrationSettingsCharge -> ProrationSettingsCharge -> Bool
(ProrationSettingsCharge -> ProrationSettingsCharge -> Bool)
-> (ProrationSettingsCharge -> ProrationSettingsCharge -> Bool)
-> Eq ProrationSettingsCharge
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProrationSettingsCharge -> ProrationSettingsCharge -> Bool
== :: ProrationSettingsCharge -> ProrationSettingsCharge -> Bool
$c/= :: ProrationSettingsCharge -> ProrationSettingsCharge -> Bool
/= :: ProrationSettingsCharge -> ProrationSettingsCharge -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON ProrationSettingsCharge where
    toJSON :: ProrationSettingsCharge -> Value
toJSON (ProrationSettingsChargeOther Value
val) = Value
val
    toJSON (ProrationSettingsChargeTyped Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
    toJSON (ProrationSettingsCharge
ProrationSettingsChargeEnumFull_amount) = Value
"full_amount"
    toJSON (ProrationSettingsCharge
ProrationSettingsChargeEnumProrated_amount) = Value
"prorated_amount"
    toJSON (ProrationSettingsCharge
ProrationSettingsChargeEnumNone) = Value
"none"
instance Data.Aeson.Types.FromJSON.FromJSON ProrationSettingsCharge where
    parseJSON :: Value -> Parser ProrationSettingsCharge
parseJSON Value
val =
        ProrationSettingsCharge -> Parser ProrationSettingsCharge
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
"full_amount" -> ProrationSettingsCharge
ProrationSettingsChargeEnumFull_amount
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"prorated_amount" -> ProrationSettingsCharge
ProrationSettingsChargeEnumProrated_amount
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"none" -> ProrationSettingsCharge
ProrationSettingsChargeEnumNone
                | Bool
GHC.Base.otherwise -> Value -> ProrationSettingsCharge
ProrationSettingsChargeOther Value
val
            )

{- | Defines the enum schema located at @components.schemas.ProrationSettings.properties.credit@ in the specification.

Determines how the amount credited is determined for this change
-}
data ProrationSettingsCredit
    = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
      ProrationSettingsCreditOther Data.Aeson.Types.Internal.Value
    | -- | This constructor can be used to send values to the server which are not present in the specification yet.
      ProrationSettingsCreditTyped Data.Text.Internal.Text
    | -- | Represents the JSON value @"full_amount"@
      ProrationSettingsCreditEnumFull_amount
    | -- | Represents the JSON value @"prorated_amount"@
      ProrationSettingsCreditEnumProrated_amount
    | -- | Represents the JSON value @"none"@
      ProrationSettingsCreditEnumNone
    deriving (Int -> ProrationSettingsCredit -> ShowS
[ProrationSettingsCredit] -> ShowS
ProrationSettingsCredit -> String
(Int -> ProrationSettingsCredit -> ShowS)
-> (ProrationSettingsCredit -> String)
-> ([ProrationSettingsCredit] -> ShowS)
-> Show ProrationSettingsCredit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProrationSettingsCredit -> ShowS
showsPrec :: Int -> ProrationSettingsCredit -> ShowS
$cshow :: ProrationSettingsCredit -> String
show :: ProrationSettingsCredit -> String
$cshowList :: [ProrationSettingsCredit] -> ShowS
showList :: [ProrationSettingsCredit] -> ShowS
GHC.Show.Show, ProrationSettingsCredit -> ProrationSettingsCredit -> Bool
(ProrationSettingsCredit -> ProrationSettingsCredit -> Bool)
-> (ProrationSettingsCredit -> ProrationSettingsCredit -> Bool)
-> Eq ProrationSettingsCredit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProrationSettingsCredit -> ProrationSettingsCredit -> Bool
== :: ProrationSettingsCredit -> ProrationSettingsCredit -> Bool
$c/= :: ProrationSettingsCredit -> ProrationSettingsCredit -> Bool
/= :: ProrationSettingsCredit -> ProrationSettingsCredit -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON ProrationSettingsCredit where
    toJSON :: ProrationSettingsCredit -> Value
toJSON (ProrationSettingsCreditOther Value
val) = Value
val
    toJSON (ProrationSettingsCreditTyped Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
    toJSON (ProrationSettingsCredit
ProrationSettingsCreditEnumFull_amount) = Value
"full_amount"
    toJSON (ProrationSettingsCredit
ProrationSettingsCreditEnumProrated_amount) = Value
"prorated_amount"
    toJSON (ProrationSettingsCredit
ProrationSettingsCreditEnumNone) = Value
"none"
instance Data.Aeson.Types.FromJSON.FromJSON ProrationSettingsCredit where
    parseJSON :: Value -> Parser ProrationSettingsCredit
parseJSON Value
val =
        ProrationSettingsCredit -> Parser ProrationSettingsCredit
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
"full_amount" -> ProrationSettingsCredit
ProrationSettingsCreditEnumFull_amount
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"prorated_amount" -> ProrationSettingsCredit
ProrationSettingsCreditEnumProrated_amount
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"none" -> ProrationSettingsCredit
ProrationSettingsCreditEnumNone
                | Bool
GHC.Base.otherwise -> Value -> ProrationSettingsCredit
ProrationSettingsCreditOther Value
val
            )