{-# 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 PortalCustomerUpdate
module StripeAPI.Types.PortalCustomerUpdate 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_customer_update@ in the specification.
data PortalCustomerUpdate = PortalCustomerUpdate
  { -- | allowed_updates: The types of customer updates that are supported. When empty, customers are not updateable.
    PortalCustomerUpdate -> [PortalCustomerUpdateAllowedUpdates']
portalCustomerUpdateAllowedUpdates :: ([PortalCustomerUpdateAllowedUpdates']),
    -- | enabled: Whether the feature is enabled.
    PortalCustomerUpdate -> Bool
portalCustomerUpdateEnabled :: GHC.Types.Bool
  }
  deriving
    ( Int -> PortalCustomerUpdate -> ShowS
[PortalCustomerUpdate] -> ShowS
PortalCustomerUpdate -> String
(Int -> PortalCustomerUpdate -> ShowS)
-> (PortalCustomerUpdate -> String)
-> ([PortalCustomerUpdate] -> ShowS)
-> Show PortalCustomerUpdate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortalCustomerUpdate] -> ShowS
$cshowList :: [PortalCustomerUpdate] -> ShowS
show :: PortalCustomerUpdate -> String
$cshow :: PortalCustomerUpdate -> String
showsPrec :: Int -> PortalCustomerUpdate -> ShowS
$cshowsPrec :: Int -> PortalCustomerUpdate -> ShowS
GHC.Show.Show,
      PortalCustomerUpdate -> PortalCustomerUpdate -> Bool
(PortalCustomerUpdate -> PortalCustomerUpdate -> Bool)
-> (PortalCustomerUpdate -> PortalCustomerUpdate -> Bool)
-> Eq PortalCustomerUpdate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortalCustomerUpdate -> PortalCustomerUpdate -> Bool
$c/= :: PortalCustomerUpdate -> PortalCustomerUpdate -> Bool
== :: PortalCustomerUpdate -> PortalCustomerUpdate -> Bool
$c== :: PortalCustomerUpdate -> PortalCustomerUpdate -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON PortalCustomerUpdate where
  toJSON :: PortalCustomerUpdate -> Value
toJSON PortalCustomerUpdate
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"allowed_updates" Text -> [PortalCustomerUpdateAllowedUpdates'] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalCustomerUpdate -> [PortalCustomerUpdateAllowedUpdates']
portalCustomerUpdateAllowedUpdates PortalCustomerUpdate
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"enabled" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalCustomerUpdate -> Bool
portalCustomerUpdateEnabled PortalCustomerUpdate
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: PortalCustomerUpdate -> Encoding
toEncoding PortalCustomerUpdate
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"allowed_updates" Text -> [PortalCustomerUpdateAllowedUpdates'] -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalCustomerUpdate -> [PortalCustomerUpdateAllowedUpdates']
portalCustomerUpdateAllowedUpdates PortalCustomerUpdate
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"enabled" Text -> Bool -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PortalCustomerUpdate -> Bool
portalCustomerUpdateEnabled PortalCustomerUpdate
obj))

instance Data.Aeson.Types.FromJSON.FromJSON PortalCustomerUpdate where
  parseJSON :: Value -> Parser PortalCustomerUpdate
parseJSON = String
-> (Object -> Parser PortalCustomerUpdate)
-> Value
-> Parser PortalCustomerUpdate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"PortalCustomerUpdate" (\Object
obj -> (([PortalCustomerUpdateAllowedUpdates']
 -> Bool -> PortalCustomerUpdate)
-> Parser
     ([PortalCustomerUpdateAllowedUpdates']
      -> Bool -> PortalCustomerUpdate)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure [PortalCustomerUpdateAllowedUpdates']
-> Bool -> PortalCustomerUpdate
PortalCustomerUpdate Parser
  ([PortalCustomerUpdateAllowedUpdates']
   -> Bool -> PortalCustomerUpdate)
-> Parser [PortalCustomerUpdateAllowedUpdates']
-> Parser (Bool -> PortalCustomerUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser [PortalCustomerUpdateAllowedUpdates']
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"allowed_updates")) Parser (Bool -> PortalCustomerUpdate)
-> Parser Bool -> Parser PortalCustomerUpdate
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"))

-- | Create a new 'PortalCustomerUpdate' with all required fields.
mkPortalCustomerUpdate ::
  -- | 'portalCustomerUpdateAllowedUpdates'
  [PortalCustomerUpdateAllowedUpdates'] ->
  -- | 'portalCustomerUpdateEnabled'
  GHC.Types.Bool ->
  PortalCustomerUpdate
mkPortalCustomerUpdate :: [PortalCustomerUpdateAllowedUpdates']
-> Bool -> PortalCustomerUpdate
mkPortalCustomerUpdate [PortalCustomerUpdateAllowedUpdates']
portalCustomerUpdateAllowedUpdates Bool
portalCustomerUpdateEnabled =
  PortalCustomerUpdate :: [PortalCustomerUpdateAllowedUpdates']
-> Bool -> PortalCustomerUpdate
PortalCustomerUpdate
    { portalCustomerUpdateAllowedUpdates :: [PortalCustomerUpdateAllowedUpdates']
portalCustomerUpdateAllowedUpdates = [PortalCustomerUpdateAllowedUpdates']
portalCustomerUpdateAllowedUpdates,
      portalCustomerUpdateEnabled :: Bool
portalCustomerUpdateEnabled = Bool
portalCustomerUpdateEnabled
    }

-- | Defines the enum schema located at @components.schemas.portal_customer_update.properties.allowed_updates.items@ in the specification.
data PortalCustomerUpdateAllowedUpdates'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    PortalCustomerUpdateAllowedUpdates'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.
    PortalCustomerUpdateAllowedUpdates'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"address"@
    PortalCustomerUpdateAllowedUpdates'EnumAddress
  | -- | Represents the JSON value @"email"@
    PortalCustomerUpdateAllowedUpdates'EnumEmail
  | -- | Represents the JSON value @"phone"@
    PortalCustomerUpdateAllowedUpdates'EnumPhone
  | -- | Represents the JSON value @"shipping"@
    PortalCustomerUpdateAllowedUpdates'EnumShipping
  | -- | Represents the JSON value @"tax_id"@
    PortalCustomerUpdateAllowedUpdates'EnumTaxId
  deriving (Int -> PortalCustomerUpdateAllowedUpdates' -> ShowS
[PortalCustomerUpdateAllowedUpdates'] -> ShowS
PortalCustomerUpdateAllowedUpdates' -> String
(Int -> PortalCustomerUpdateAllowedUpdates' -> ShowS)
-> (PortalCustomerUpdateAllowedUpdates' -> String)
-> ([PortalCustomerUpdateAllowedUpdates'] -> ShowS)
-> Show PortalCustomerUpdateAllowedUpdates'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortalCustomerUpdateAllowedUpdates'] -> ShowS
$cshowList :: [PortalCustomerUpdateAllowedUpdates'] -> ShowS
show :: PortalCustomerUpdateAllowedUpdates' -> String
$cshow :: PortalCustomerUpdateAllowedUpdates' -> String
showsPrec :: Int -> PortalCustomerUpdateAllowedUpdates' -> ShowS
$cshowsPrec :: Int -> PortalCustomerUpdateAllowedUpdates' -> ShowS
GHC.Show.Show, PortalCustomerUpdateAllowedUpdates'
-> PortalCustomerUpdateAllowedUpdates' -> Bool
(PortalCustomerUpdateAllowedUpdates'
 -> PortalCustomerUpdateAllowedUpdates' -> Bool)
-> (PortalCustomerUpdateAllowedUpdates'
    -> PortalCustomerUpdateAllowedUpdates' -> Bool)
-> Eq PortalCustomerUpdateAllowedUpdates'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortalCustomerUpdateAllowedUpdates'
-> PortalCustomerUpdateAllowedUpdates' -> Bool
$c/= :: PortalCustomerUpdateAllowedUpdates'
-> PortalCustomerUpdateAllowedUpdates' -> Bool
== :: PortalCustomerUpdateAllowedUpdates'
-> PortalCustomerUpdateAllowedUpdates' -> Bool
$c== :: PortalCustomerUpdateAllowedUpdates'
-> PortalCustomerUpdateAllowedUpdates' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON PortalCustomerUpdateAllowedUpdates' where
  toJSON :: PortalCustomerUpdateAllowedUpdates' -> Value
toJSON (PortalCustomerUpdateAllowedUpdates'Other Value
val) = Value
val
  toJSON (PortalCustomerUpdateAllowedUpdates'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumAddress) = Value
"address"
  toJSON (PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumEmail) = Value
"email"
  toJSON (PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumPhone) = Value
"phone"
  toJSON (PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumShipping) = Value
"shipping"
  toJSON (PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumTaxId) = Value
"tax_id"

instance Data.Aeson.Types.FromJSON.FromJSON PortalCustomerUpdateAllowedUpdates' where
  parseJSON :: Value -> Parser PortalCustomerUpdateAllowedUpdates'
parseJSON Value
val =
    PortalCustomerUpdateAllowedUpdates'
-> Parser PortalCustomerUpdateAllowedUpdates'
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
"address" -> PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumAddress
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"email" -> PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumEmail
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"phone" -> PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumPhone
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"shipping" -> PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumShipping
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"tax_id" -> PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'EnumTaxId
            | Bool
GHC.Base.otherwise -> Value -> PortalCustomerUpdateAllowedUpdates'
PortalCustomerUpdateAllowedUpdates'Other Value
val
      )