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

-- | Defines the object schema located at @components.schemas.recurring@ in the specification.
data Recurring = Recurring
  { -- | aggregate_usage: Specifies a usage aggregation strategy for prices of \`usage_type=metered\`. Allowed values are \`sum\` for summing up all usage during a period, \`last_during_period\` for using the last usage record reported within a period, \`last_ever\` for using the last usage record ever (across period bounds) or \`max\` which uses the usage record with the maximum reported usage during a period. Defaults to \`sum\`.
    Recurring -> Maybe RecurringAggregateUsage'
recurringAggregateUsage :: (GHC.Maybe.Maybe RecurringAggregateUsage'),
    -- | interval: The frequency at which a subscription is billed. One of \`day\`, \`week\`, \`month\` or \`year\`.
    Recurring -> RecurringInterval'
recurringInterval :: RecurringInterval',
    -- | interval_count: The number of intervals (specified in the \`interval\` attribute) between subscription billings. For example, \`interval=month\` and \`interval_count=3\` bills every 3 months.
    Recurring -> Int
recurringIntervalCount :: GHC.Types.Int,
    -- | usage_type: Configures how the quantity per period should be determined. Can be either \`metered\` or \`licensed\`. \`licensed\` automatically bills the \`quantity\` set when adding it to a subscription. \`metered\` aggregates the total usage based on usage records. Defaults to \`licensed\`.
    Recurring -> RecurringUsageType'
recurringUsageType :: RecurringUsageType'
  }
  deriving
    ( Int -> Recurring -> ShowS
[Recurring] -> ShowS
Recurring -> String
(Int -> Recurring -> ShowS)
-> (Recurring -> String)
-> ([Recurring] -> ShowS)
-> Show Recurring
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Recurring] -> ShowS
$cshowList :: [Recurring] -> ShowS
show :: Recurring -> String
$cshow :: Recurring -> String
showsPrec :: Int -> Recurring -> ShowS
$cshowsPrec :: Int -> Recurring -> ShowS
GHC.Show.Show,
      Recurring -> Recurring -> Bool
(Recurring -> Recurring -> Bool)
-> (Recurring -> Recurring -> Bool) -> Eq Recurring
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Recurring -> Recurring -> Bool
$c/= :: Recurring -> Recurring -> Bool
== :: Recurring -> Recurring -> Bool
$c== :: Recurring -> Recurring -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON Recurring where
  toJSON :: Recurring -> Value
toJSON Recurring
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"aggregate_usage" Text -> Maybe RecurringAggregateUsage' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Recurring -> Maybe RecurringAggregateUsage'
recurringAggregateUsage Recurring
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"interval" Text -> RecurringInterval' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Recurring -> RecurringInterval'
recurringInterval Recurring
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"interval_count" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Recurring -> Int
recurringIntervalCount Recurring
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"usage_type" Text -> RecurringUsageType' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Recurring -> RecurringUsageType'
recurringUsageType Recurring
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: Recurring -> Encoding
toEncoding Recurring
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"aggregate_usage" Text -> Maybe RecurringAggregateUsage' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Recurring -> Maybe RecurringAggregateUsage'
recurringAggregateUsage Recurring
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"interval" Text -> RecurringInterval' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Recurring -> RecurringInterval'
recurringInterval Recurring
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"interval_count" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Recurring -> Int
recurringIntervalCount Recurring
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"usage_type" Text -> RecurringUsageType' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= Recurring -> RecurringUsageType'
recurringUsageType Recurring
obj))))

instance Data.Aeson.Types.FromJSON.FromJSON Recurring where
  parseJSON :: Value -> Parser Recurring
parseJSON = String -> (Object -> Parser Recurring) -> Value -> Parser Recurring
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"Recurring" (\Object
obj -> ((((Maybe RecurringAggregateUsage'
 -> RecurringInterval' -> Int -> RecurringUsageType' -> Recurring)
-> Parser
     (Maybe RecurringAggregateUsage'
      -> RecurringInterval' -> Int -> RecurringUsageType' -> Recurring)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe RecurringAggregateUsage'
-> RecurringInterval' -> Int -> RecurringUsageType' -> Recurring
Recurring Parser
  (Maybe RecurringAggregateUsage'
   -> RecurringInterval' -> Int -> RecurringUsageType' -> Recurring)
-> Parser (Maybe RecurringAggregateUsage')
-> Parser
     (RecurringInterval' -> Int -> RecurringUsageType' -> Recurring)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe RecurringAggregateUsage')
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"aggregate_usage")) Parser
  (RecurringInterval' -> Int -> RecurringUsageType' -> Recurring)
-> Parser RecurringInterval'
-> Parser (Int -> RecurringUsageType' -> Recurring)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser RecurringInterval'
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"interval")) Parser (Int -> RecurringUsageType' -> Recurring)
-> Parser Int -> Parser (RecurringUsageType' -> Recurring)
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
"interval_count")) Parser (RecurringUsageType' -> Recurring)
-> Parser RecurringUsageType' -> Parser Recurring
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser RecurringUsageType'
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"usage_type"))

-- | Create a new 'Recurring' with all required fields.
mkRecurring ::
  -- | 'recurringInterval'
  RecurringInterval' ->
  -- | 'recurringIntervalCount'
  GHC.Types.Int ->
  -- | 'recurringUsageType'
  RecurringUsageType' ->
  Recurring
mkRecurring :: RecurringInterval' -> Int -> RecurringUsageType' -> Recurring
mkRecurring RecurringInterval'
recurringInterval Int
recurringIntervalCount RecurringUsageType'
recurringUsageType =
  Recurring :: Maybe RecurringAggregateUsage'
-> RecurringInterval' -> Int -> RecurringUsageType' -> Recurring
Recurring
    { recurringAggregateUsage :: Maybe RecurringAggregateUsage'
recurringAggregateUsage = Maybe RecurringAggregateUsage'
forall a. Maybe a
GHC.Maybe.Nothing,
      recurringInterval :: RecurringInterval'
recurringInterval = RecurringInterval'
recurringInterval,
      recurringIntervalCount :: Int
recurringIntervalCount = Int
recurringIntervalCount,
      recurringUsageType :: RecurringUsageType'
recurringUsageType = RecurringUsageType'
recurringUsageType
    }

-- | Defines the enum schema located at @components.schemas.recurring.properties.aggregate_usage@ in the specification.
--
-- Specifies a usage aggregation strategy for prices of \`usage_type=metered\`. Allowed values are \`sum\` for summing up all usage during a period, \`last_during_period\` for using the last usage record reported within a period, \`last_ever\` for using the last usage record ever (across period bounds) or \`max\` which uses the usage record with the maximum reported usage during a period. Defaults to \`sum\`.
data RecurringAggregateUsage'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    RecurringAggregateUsage'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.
    RecurringAggregateUsage'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"last_during_period"@
    RecurringAggregateUsage'EnumLastDuringPeriod
  | -- | Represents the JSON value @"last_ever"@
    RecurringAggregateUsage'EnumLastEver
  | -- | Represents the JSON value @"max"@
    RecurringAggregateUsage'EnumMax
  | -- | Represents the JSON value @"sum"@
    RecurringAggregateUsage'EnumSum
  deriving (Int -> RecurringAggregateUsage' -> ShowS
[RecurringAggregateUsage'] -> ShowS
RecurringAggregateUsage' -> String
(Int -> RecurringAggregateUsage' -> ShowS)
-> (RecurringAggregateUsage' -> String)
-> ([RecurringAggregateUsage'] -> ShowS)
-> Show RecurringAggregateUsage'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecurringAggregateUsage'] -> ShowS
$cshowList :: [RecurringAggregateUsage'] -> ShowS
show :: RecurringAggregateUsage' -> String
$cshow :: RecurringAggregateUsage' -> String
showsPrec :: Int -> RecurringAggregateUsage' -> ShowS
$cshowsPrec :: Int -> RecurringAggregateUsage' -> ShowS
GHC.Show.Show, RecurringAggregateUsage' -> RecurringAggregateUsage' -> Bool
(RecurringAggregateUsage' -> RecurringAggregateUsage' -> Bool)
-> (RecurringAggregateUsage' -> RecurringAggregateUsage' -> Bool)
-> Eq RecurringAggregateUsage'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecurringAggregateUsage' -> RecurringAggregateUsage' -> Bool
$c/= :: RecurringAggregateUsage' -> RecurringAggregateUsage' -> Bool
== :: RecurringAggregateUsage' -> RecurringAggregateUsage' -> Bool
$c== :: RecurringAggregateUsage' -> RecurringAggregateUsage' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON RecurringAggregateUsage' where
  toJSON :: RecurringAggregateUsage' -> Value
toJSON (RecurringAggregateUsage'Other Value
val) = Value
val
  toJSON (RecurringAggregateUsage'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (RecurringAggregateUsage'
RecurringAggregateUsage'EnumLastDuringPeriod) = Value
"last_during_period"
  toJSON (RecurringAggregateUsage'
RecurringAggregateUsage'EnumLastEver) = Value
"last_ever"
  toJSON (RecurringAggregateUsage'
RecurringAggregateUsage'EnumMax) = Value
"max"
  toJSON (RecurringAggregateUsage'
RecurringAggregateUsage'EnumSum) = Value
"sum"

instance Data.Aeson.Types.FromJSON.FromJSON RecurringAggregateUsage' where
  parseJSON :: Value -> Parser RecurringAggregateUsage'
parseJSON Value
val =
    RecurringAggregateUsage' -> Parser RecurringAggregateUsage'
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
"last_during_period" -> RecurringAggregateUsage'
RecurringAggregateUsage'EnumLastDuringPeriod
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"last_ever" -> RecurringAggregateUsage'
RecurringAggregateUsage'EnumLastEver
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"max" -> RecurringAggregateUsage'
RecurringAggregateUsage'EnumMax
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"sum" -> RecurringAggregateUsage'
RecurringAggregateUsage'EnumSum
            | Bool
GHC.Base.otherwise -> Value -> RecurringAggregateUsage'
RecurringAggregateUsage'Other Value
val
      )

-- | Defines the enum schema located at @components.schemas.recurring.properties.interval@ in the specification.
--
-- The frequency at which a subscription is billed. One of \`day\`, \`week\`, \`month\` or \`year\`.
data RecurringInterval'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    RecurringInterval'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.
    RecurringInterval'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"day"@
    RecurringInterval'EnumDay
  | -- | Represents the JSON value @"month"@
    RecurringInterval'EnumMonth
  | -- | Represents the JSON value @"week"@
    RecurringInterval'EnumWeek
  | -- | Represents the JSON value @"year"@
    RecurringInterval'EnumYear
  deriving (Int -> RecurringInterval' -> ShowS
[RecurringInterval'] -> ShowS
RecurringInterval' -> String
(Int -> RecurringInterval' -> ShowS)
-> (RecurringInterval' -> String)
-> ([RecurringInterval'] -> ShowS)
-> Show RecurringInterval'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecurringInterval'] -> ShowS
$cshowList :: [RecurringInterval'] -> ShowS
show :: RecurringInterval' -> String
$cshow :: RecurringInterval' -> String
showsPrec :: Int -> RecurringInterval' -> ShowS
$cshowsPrec :: Int -> RecurringInterval' -> ShowS
GHC.Show.Show, RecurringInterval' -> RecurringInterval' -> Bool
(RecurringInterval' -> RecurringInterval' -> Bool)
-> (RecurringInterval' -> RecurringInterval' -> Bool)
-> Eq RecurringInterval'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecurringInterval' -> RecurringInterval' -> Bool
$c/= :: RecurringInterval' -> RecurringInterval' -> Bool
== :: RecurringInterval' -> RecurringInterval' -> Bool
$c== :: RecurringInterval' -> RecurringInterval' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON RecurringInterval' where
  toJSON :: RecurringInterval' -> Value
toJSON (RecurringInterval'Other Value
val) = Value
val
  toJSON (RecurringInterval'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (RecurringInterval'
RecurringInterval'EnumDay) = Value
"day"
  toJSON (RecurringInterval'
RecurringInterval'EnumMonth) = Value
"month"
  toJSON (RecurringInterval'
RecurringInterval'EnumWeek) = Value
"week"
  toJSON (RecurringInterval'
RecurringInterval'EnumYear) = Value
"year"

instance Data.Aeson.Types.FromJSON.FromJSON RecurringInterval' where
  parseJSON :: Value -> Parser RecurringInterval'
parseJSON Value
val =
    RecurringInterval' -> Parser RecurringInterval'
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" -> RecurringInterval'
RecurringInterval'EnumDay
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"month" -> RecurringInterval'
RecurringInterval'EnumMonth
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"week" -> RecurringInterval'
RecurringInterval'EnumWeek
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"year" -> RecurringInterval'
RecurringInterval'EnumYear
            | Bool
GHC.Base.otherwise -> Value -> RecurringInterval'
RecurringInterval'Other Value
val
      )

-- | Defines the enum schema located at @components.schemas.recurring.properties.usage_type@ in the specification.
--
-- Configures how the quantity per period should be determined. Can be either \`metered\` or \`licensed\`. \`licensed\` automatically bills the \`quantity\` set when adding it to a subscription. \`metered\` aggregates the total usage based on usage records. Defaults to \`licensed\`.
data RecurringUsageType'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    RecurringUsageType'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.
    RecurringUsageType'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"licensed"@
    RecurringUsageType'EnumLicensed
  | -- | Represents the JSON value @"metered"@
    RecurringUsageType'EnumMetered
  deriving (Int -> RecurringUsageType' -> ShowS
[RecurringUsageType'] -> ShowS
RecurringUsageType' -> String
(Int -> RecurringUsageType' -> ShowS)
-> (RecurringUsageType' -> String)
-> ([RecurringUsageType'] -> ShowS)
-> Show RecurringUsageType'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RecurringUsageType'] -> ShowS
$cshowList :: [RecurringUsageType'] -> ShowS
show :: RecurringUsageType' -> String
$cshow :: RecurringUsageType' -> String
showsPrec :: Int -> RecurringUsageType' -> ShowS
$cshowsPrec :: Int -> RecurringUsageType' -> ShowS
GHC.Show.Show, RecurringUsageType' -> RecurringUsageType' -> Bool
(RecurringUsageType' -> RecurringUsageType' -> Bool)
-> (RecurringUsageType' -> RecurringUsageType' -> Bool)
-> Eq RecurringUsageType'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RecurringUsageType' -> RecurringUsageType' -> Bool
$c/= :: RecurringUsageType' -> RecurringUsageType' -> Bool
== :: RecurringUsageType' -> RecurringUsageType' -> Bool
$c== :: RecurringUsageType' -> RecurringUsageType' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON RecurringUsageType' where
  toJSON :: RecurringUsageType' -> Value
toJSON (RecurringUsageType'Other Value
val) = Value
val
  toJSON (RecurringUsageType'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (RecurringUsageType'
RecurringUsageType'EnumLicensed) = Value
"licensed"
  toJSON (RecurringUsageType'
RecurringUsageType'EnumMetered) = Value
"metered"

instance Data.Aeson.Types.FromJSON.FromJSON RecurringUsageType' where
  parseJSON :: Value -> Parser RecurringUsageType'
parseJSON Value
val =
    RecurringUsageType' -> Parser RecurringUsageType'
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
"licensed" -> RecurringUsageType'
RecurringUsageType'EnumLicensed
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"metered" -> RecurringUsageType'
RecurringUsageType'EnumMetered
            | Bool
GHC.Base.otherwise -> Value -> RecurringUsageType'
RecurringUsageType'Other Value
val
      )