{-# 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 PortalSubscriptionCancel
module StripeAPI.Types.PortalSubscriptionCancel 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.portal_subscription_cancel@ in the specification.
data PortalSubscriptionCancel = PortalSubscriptionCancel
  { -- | enabled: Whether the feature is enabled.
    PortalSubscriptionCancel -> Bool
portalSubscriptionCancelEnabled :: GHC.Types.Bool,
    -- | mode: Whether to cancel subscriptions immediately or at the end of the billing period.
    PortalSubscriptionCancel -> PortalSubscriptionCancelMode'
portalSubscriptionCancelMode :: PortalSubscriptionCancelMode',
    -- | proration_behavior: Whether to create prorations when canceling subscriptions. Possible values are \`none\` and \`create_prorations\`.
    PortalSubscriptionCancel
-> PortalSubscriptionCancelProrationBehavior'
portalSubscriptionCancelProrationBehavior :: PortalSubscriptionCancelProrationBehavior'
  }
  deriving
    ( Int -> PortalSubscriptionCancel -> ShowS
[PortalSubscriptionCancel] -> ShowS
PortalSubscriptionCancel -> String
(Int -> PortalSubscriptionCancel -> ShowS)
-> (PortalSubscriptionCancel -> String)
-> ([PortalSubscriptionCancel] -> ShowS)
-> Show PortalSubscriptionCancel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortalSubscriptionCancel] -> ShowS
$cshowList :: [PortalSubscriptionCancel] -> ShowS
show :: PortalSubscriptionCancel -> String
$cshow :: PortalSubscriptionCancel -> String
showsPrec :: Int -> PortalSubscriptionCancel -> ShowS
$cshowsPrec :: Int -> PortalSubscriptionCancel -> ShowS
GHC.Show.Show,
      PortalSubscriptionCancel -> PortalSubscriptionCancel -> Bool
(PortalSubscriptionCancel -> PortalSubscriptionCancel -> Bool)
-> (PortalSubscriptionCancel -> PortalSubscriptionCancel -> Bool)
-> Eq PortalSubscriptionCancel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortalSubscriptionCancel -> PortalSubscriptionCancel -> Bool
$c/= :: PortalSubscriptionCancel -> PortalSubscriptionCancel -> Bool
== :: PortalSubscriptionCancel -> PortalSubscriptionCancel -> Bool
$c== :: PortalSubscriptionCancel -> PortalSubscriptionCancel -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON PortalSubscriptionCancel where
  toJSON :: PortalSubscriptionCancel -> Value
toJSON PortalSubscriptionCancel
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"enabled" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalSubscriptionCancel -> Bool
portalSubscriptionCancelEnabled PortalSubscriptionCancel
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"mode" Text -> PortalSubscriptionCancelMode' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalSubscriptionCancel -> PortalSubscriptionCancelMode'
portalSubscriptionCancelMode PortalSubscriptionCancel
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"proration_behavior" Text -> PortalSubscriptionCancelProrationBehavior' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalSubscriptionCancel
-> PortalSubscriptionCancelProrationBehavior'
portalSubscriptionCancelProrationBehavior PortalSubscriptionCancel
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: PortalSubscriptionCancel -> Encoding
toEncoding PortalSubscriptionCancel
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"enabled" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalSubscriptionCancel -> Bool
portalSubscriptionCancelEnabled PortalSubscriptionCancel
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"mode" Text -> PortalSubscriptionCancelMode' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalSubscriptionCancel -> PortalSubscriptionCancelMode'
portalSubscriptionCancelMode PortalSubscriptionCancel
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"proration_behavior" Text -> PortalSubscriptionCancelProrationBehavior' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalSubscriptionCancel
-> PortalSubscriptionCancelProrationBehavior'
portalSubscriptionCancelProrationBehavior PortalSubscriptionCancel
obj)))

instance Data.Aeson.Types.FromJSON.FromJSON PortalSubscriptionCancel where
  parseJSON :: Value -> Parser PortalSubscriptionCancel
parseJSON = String
-> (Object -> Parser PortalSubscriptionCancel)
-> Value
-> Parser PortalSubscriptionCancel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"PortalSubscriptionCancel" (\Object
obj -> (((Bool
 -> PortalSubscriptionCancelMode'
 -> PortalSubscriptionCancelProrationBehavior'
 -> PortalSubscriptionCancel)
-> Parser
     (Bool
      -> PortalSubscriptionCancelMode'
      -> PortalSubscriptionCancelProrationBehavior'
      -> PortalSubscriptionCancel)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Bool
-> PortalSubscriptionCancelMode'
-> PortalSubscriptionCancelProrationBehavior'
-> PortalSubscriptionCancel
PortalSubscriptionCancel Parser
  (Bool
   -> PortalSubscriptionCancelMode'
   -> PortalSubscriptionCancelProrationBehavior'
   -> PortalSubscriptionCancel)
-> Parser Bool
-> Parser
     (PortalSubscriptionCancelMode'
      -> PortalSubscriptionCancelProrationBehavior'
      -> PortalSubscriptionCancel)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"enabled")) Parser
  (PortalSubscriptionCancelMode'
   -> PortalSubscriptionCancelProrationBehavior'
   -> PortalSubscriptionCancel)
-> Parser PortalSubscriptionCancelMode'
-> Parser
     (PortalSubscriptionCancelProrationBehavior'
      -> PortalSubscriptionCancel)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser PortalSubscriptionCancelMode'
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"mode")) Parser
  (PortalSubscriptionCancelProrationBehavior'
   -> PortalSubscriptionCancel)
-> Parser PortalSubscriptionCancelProrationBehavior'
-> Parser PortalSubscriptionCancel
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser PortalSubscriptionCancelProrationBehavior'
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"proration_behavior"))

-- | Create a new 'PortalSubscriptionCancel' with all required fields.
mkPortalSubscriptionCancel ::
  -- | 'portalSubscriptionCancelEnabled'
  GHC.Types.Bool ->
  -- | 'portalSubscriptionCancelMode'
  PortalSubscriptionCancelMode' ->
  -- | 'portalSubscriptionCancelProrationBehavior'
  PortalSubscriptionCancelProrationBehavior' ->
  PortalSubscriptionCancel
mkPortalSubscriptionCancel :: Bool
-> PortalSubscriptionCancelMode'
-> PortalSubscriptionCancelProrationBehavior'
-> PortalSubscriptionCancel
mkPortalSubscriptionCancel Bool
portalSubscriptionCancelEnabled PortalSubscriptionCancelMode'
portalSubscriptionCancelMode PortalSubscriptionCancelProrationBehavior'
portalSubscriptionCancelProrationBehavior =
  PortalSubscriptionCancel :: Bool
-> PortalSubscriptionCancelMode'
-> PortalSubscriptionCancelProrationBehavior'
-> PortalSubscriptionCancel
PortalSubscriptionCancel
    { portalSubscriptionCancelEnabled :: Bool
portalSubscriptionCancelEnabled = Bool
portalSubscriptionCancelEnabled,
      portalSubscriptionCancelMode :: PortalSubscriptionCancelMode'
portalSubscriptionCancelMode = PortalSubscriptionCancelMode'
portalSubscriptionCancelMode,
      portalSubscriptionCancelProrationBehavior :: PortalSubscriptionCancelProrationBehavior'
portalSubscriptionCancelProrationBehavior = PortalSubscriptionCancelProrationBehavior'
portalSubscriptionCancelProrationBehavior
    }

-- | Defines the enum schema located at @components.schemas.portal_subscription_cancel.properties.mode@ in the specification.
--
-- Whether to cancel subscriptions immediately or at the end of the billing period.
data PortalSubscriptionCancelMode'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    PortalSubscriptionCancelMode'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.
    PortalSubscriptionCancelMode'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"at_period_end"@
    PortalSubscriptionCancelMode'EnumAtPeriodEnd
  | -- | Represents the JSON value @"immediately"@
    PortalSubscriptionCancelMode'EnumImmediately
  deriving (Int -> PortalSubscriptionCancelMode' -> ShowS
[PortalSubscriptionCancelMode'] -> ShowS
PortalSubscriptionCancelMode' -> String
(Int -> PortalSubscriptionCancelMode' -> ShowS)
-> (PortalSubscriptionCancelMode' -> String)
-> ([PortalSubscriptionCancelMode'] -> ShowS)
-> Show PortalSubscriptionCancelMode'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortalSubscriptionCancelMode'] -> ShowS
$cshowList :: [PortalSubscriptionCancelMode'] -> ShowS
show :: PortalSubscriptionCancelMode' -> String
$cshow :: PortalSubscriptionCancelMode' -> String
showsPrec :: Int -> PortalSubscriptionCancelMode' -> ShowS
$cshowsPrec :: Int -> PortalSubscriptionCancelMode' -> ShowS
GHC.Show.Show, PortalSubscriptionCancelMode'
-> PortalSubscriptionCancelMode' -> Bool
(PortalSubscriptionCancelMode'
 -> PortalSubscriptionCancelMode' -> Bool)
-> (PortalSubscriptionCancelMode'
    -> PortalSubscriptionCancelMode' -> Bool)
-> Eq PortalSubscriptionCancelMode'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortalSubscriptionCancelMode'
-> PortalSubscriptionCancelMode' -> Bool
$c/= :: PortalSubscriptionCancelMode'
-> PortalSubscriptionCancelMode' -> Bool
== :: PortalSubscriptionCancelMode'
-> PortalSubscriptionCancelMode' -> Bool
$c== :: PortalSubscriptionCancelMode'
-> PortalSubscriptionCancelMode' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON PortalSubscriptionCancelMode' where
  toJSON :: PortalSubscriptionCancelMode' -> Value
toJSON (PortalSubscriptionCancelMode'Other Value
val) = Value
val
  toJSON (PortalSubscriptionCancelMode'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (PortalSubscriptionCancelMode'
PortalSubscriptionCancelMode'EnumAtPeriodEnd) = Value
"at_period_end"
  toJSON (PortalSubscriptionCancelMode'
PortalSubscriptionCancelMode'EnumImmediately) = Value
"immediately"

instance Data.Aeson.Types.FromJSON.FromJSON PortalSubscriptionCancelMode' where
  parseJSON :: Value -> Parser PortalSubscriptionCancelMode'
parseJSON Value
val =
    PortalSubscriptionCancelMode'
-> Parser PortalSubscriptionCancelMode'
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
"at_period_end" -> PortalSubscriptionCancelMode'
PortalSubscriptionCancelMode'EnumAtPeriodEnd
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"immediately" -> PortalSubscriptionCancelMode'
PortalSubscriptionCancelMode'EnumImmediately
            | Bool
GHC.Base.otherwise -> Value -> PortalSubscriptionCancelMode'
PortalSubscriptionCancelMode'Other Value
val
      )

-- | Defines the enum schema located at @components.schemas.portal_subscription_cancel.properties.proration_behavior@ in the specification.
--
-- Whether to create prorations when canceling subscriptions. Possible values are \`none\` and \`create_prorations\`.
data PortalSubscriptionCancelProrationBehavior'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    PortalSubscriptionCancelProrationBehavior'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.
    PortalSubscriptionCancelProrationBehavior'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"always_invoice"@
    PortalSubscriptionCancelProrationBehavior'EnumAlwaysInvoice
  | -- | Represents the JSON value @"create_prorations"@
    PortalSubscriptionCancelProrationBehavior'EnumCreateProrations
  | -- | Represents the JSON value @"none"@
    PortalSubscriptionCancelProrationBehavior'EnumNone
  deriving (Int -> PortalSubscriptionCancelProrationBehavior' -> ShowS
[PortalSubscriptionCancelProrationBehavior'] -> ShowS
PortalSubscriptionCancelProrationBehavior' -> String
(Int -> PortalSubscriptionCancelProrationBehavior' -> ShowS)
-> (PortalSubscriptionCancelProrationBehavior' -> String)
-> ([PortalSubscriptionCancelProrationBehavior'] -> ShowS)
-> Show PortalSubscriptionCancelProrationBehavior'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortalSubscriptionCancelProrationBehavior'] -> ShowS
$cshowList :: [PortalSubscriptionCancelProrationBehavior'] -> ShowS
show :: PortalSubscriptionCancelProrationBehavior' -> String
$cshow :: PortalSubscriptionCancelProrationBehavior' -> String
showsPrec :: Int -> PortalSubscriptionCancelProrationBehavior' -> ShowS
$cshowsPrec :: Int -> PortalSubscriptionCancelProrationBehavior' -> ShowS
GHC.Show.Show, PortalSubscriptionCancelProrationBehavior'
-> PortalSubscriptionCancelProrationBehavior' -> Bool
(PortalSubscriptionCancelProrationBehavior'
 -> PortalSubscriptionCancelProrationBehavior' -> Bool)
-> (PortalSubscriptionCancelProrationBehavior'
    -> PortalSubscriptionCancelProrationBehavior' -> Bool)
-> Eq PortalSubscriptionCancelProrationBehavior'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortalSubscriptionCancelProrationBehavior'
-> PortalSubscriptionCancelProrationBehavior' -> Bool
$c/= :: PortalSubscriptionCancelProrationBehavior'
-> PortalSubscriptionCancelProrationBehavior' -> Bool
== :: PortalSubscriptionCancelProrationBehavior'
-> PortalSubscriptionCancelProrationBehavior' -> Bool
$c== :: PortalSubscriptionCancelProrationBehavior'
-> PortalSubscriptionCancelProrationBehavior' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON PortalSubscriptionCancelProrationBehavior' where
  toJSON :: PortalSubscriptionCancelProrationBehavior' -> Value
toJSON (PortalSubscriptionCancelProrationBehavior'Other Value
val) = Value
val
  toJSON (PortalSubscriptionCancelProrationBehavior'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (PortalSubscriptionCancelProrationBehavior'
PortalSubscriptionCancelProrationBehavior'EnumAlwaysInvoice) = Value
"always_invoice"
  toJSON (PortalSubscriptionCancelProrationBehavior'
PortalSubscriptionCancelProrationBehavior'EnumCreateProrations) = Value
"create_prorations"
  toJSON (PortalSubscriptionCancelProrationBehavior'
PortalSubscriptionCancelProrationBehavior'EnumNone) = Value
"none"

instance Data.Aeson.Types.FromJSON.FromJSON PortalSubscriptionCancelProrationBehavior' where
  parseJSON :: Value -> Parser PortalSubscriptionCancelProrationBehavior'
parseJSON Value
val =
    PortalSubscriptionCancelProrationBehavior'
-> Parser PortalSubscriptionCancelProrationBehavior'
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
"always_invoice" -> PortalSubscriptionCancelProrationBehavior'
PortalSubscriptionCancelProrationBehavior'EnumAlwaysInvoice
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"create_prorations" -> PortalSubscriptionCancelProrationBehavior'
PortalSubscriptionCancelProrationBehavior'EnumCreateProrations
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"none" -> PortalSubscriptionCancelProrationBehavior'
PortalSubscriptionCancelProrationBehavior'EnumNone
            | Bool
GHC.Base.otherwise -> Value -> PortalSubscriptionCancelProrationBehavior'
PortalSubscriptionCancelProrationBehavior'Other Value
val
      )