{-# 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 AutomaticTax
module StripeAPI.Types.AutomaticTax 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.automatic_tax@ in the specification.
data AutomaticTax = AutomaticTax
  { -- | enabled: Whether Stripe automatically computes tax on this invoice.
    AutomaticTax -> Bool
automaticTaxEnabled :: GHC.Types.Bool,
    -- | status: The status of the most recent automated tax calculation for this invoice.
    AutomaticTax -> Maybe AutomaticTaxStatus'
automaticTaxStatus :: (GHC.Maybe.Maybe AutomaticTaxStatus')
  }
  deriving
    ( Int -> AutomaticTax -> ShowS
[AutomaticTax] -> ShowS
AutomaticTax -> String
(Int -> AutomaticTax -> ShowS)
-> (AutomaticTax -> String)
-> ([AutomaticTax] -> ShowS)
-> Show AutomaticTax
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutomaticTax] -> ShowS
$cshowList :: [AutomaticTax] -> ShowS
show :: AutomaticTax -> String
$cshow :: AutomaticTax -> String
showsPrec :: Int -> AutomaticTax -> ShowS
$cshowsPrec :: Int -> AutomaticTax -> ShowS
GHC.Show.Show,
      AutomaticTax -> AutomaticTax -> Bool
(AutomaticTax -> AutomaticTax -> Bool)
-> (AutomaticTax -> AutomaticTax -> Bool) -> Eq AutomaticTax
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutomaticTax -> AutomaticTax -> Bool
$c/= :: AutomaticTax -> AutomaticTax -> Bool
== :: AutomaticTax -> AutomaticTax -> Bool
$c== :: AutomaticTax -> AutomaticTax -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON AutomaticTax where
  toJSON :: AutomaticTax -> Value
toJSON AutomaticTax
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..= AutomaticTax -> Bool
automaticTaxEnabled AutomaticTax
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"status" Text -> Maybe AutomaticTaxStatus' -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= AutomaticTax -> Maybe AutomaticTaxStatus'
automaticTaxStatus AutomaticTax
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: AutomaticTax -> Encoding
toEncoding AutomaticTax
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..= AutomaticTax -> Bool
automaticTaxEnabled AutomaticTax
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"status" Text -> Maybe AutomaticTaxStatus' -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= AutomaticTax -> Maybe AutomaticTaxStatus'
automaticTaxStatus AutomaticTax
obj))

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

-- | Create a new 'AutomaticTax' with all required fields.
mkAutomaticTax ::
  -- | 'automaticTaxEnabled'
  GHC.Types.Bool ->
  AutomaticTax
mkAutomaticTax :: Bool -> AutomaticTax
mkAutomaticTax Bool
automaticTaxEnabled =
  AutomaticTax :: Bool -> Maybe AutomaticTaxStatus' -> AutomaticTax
AutomaticTax
    { automaticTaxEnabled :: Bool
automaticTaxEnabled = Bool
automaticTaxEnabled,
      automaticTaxStatus :: Maybe AutomaticTaxStatus'
automaticTaxStatus = Maybe AutomaticTaxStatus'
forall a. Maybe a
GHC.Maybe.Nothing
    }

-- | Defines the enum schema located at @components.schemas.automatic_tax.properties.status@ in the specification.
--
-- The status of the most recent automated tax calculation for this invoice.
data AutomaticTaxStatus'
  = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
    AutomaticTaxStatus'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.
    AutomaticTaxStatus'Typed Data.Text.Internal.Text
  | -- | Represents the JSON value @"complete"@
    AutomaticTaxStatus'EnumComplete
  | -- | Represents the JSON value @"failed"@
    AutomaticTaxStatus'EnumFailed
  | -- | Represents the JSON value @"requires_location_inputs"@
    AutomaticTaxStatus'EnumRequiresLocationInputs
  deriving (Int -> AutomaticTaxStatus' -> ShowS
[AutomaticTaxStatus'] -> ShowS
AutomaticTaxStatus' -> String
(Int -> AutomaticTaxStatus' -> ShowS)
-> (AutomaticTaxStatus' -> String)
-> ([AutomaticTaxStatus'] -> ShowS)
-> Show AutomaticTaxStatus'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutomaticTaxStatus'] -> ShowS
$cshowList :: [AutomaticTaxStatus'] -> ShowS
show :: AutomaticTaxStatus' -> String
$cshow :: AutomaticTaxStatus' -> String
showsPrec :: Int -> AutomaticTaxStatus' -> ShowS
$cshowsPrec :: Int -> AutomaticTaxStatus' -> ShowS
GHC.Show.Show, AutomaticTaxStatus' -> AutomaticTaxStatus' -> Bool
(AutomaticTaxStatus' -> AutomaticTaxStatus' -> Bool)
-> (AutomaticTaxStatus' -> AutomaticTaxStatus' -> Bool)
-> Eq AutomaticTaxStatus'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutomaticTaxStatus' -> AutomaticTaxStatus' -> Bool
$c/= :: AutomaticTaxStatus' -> AutomaticTaxStatus' -> Bool
== :: AutomaticTaxStatus' -> AutomaticTaxStatus' -> Bool
$c== :: AutomaticTaxStatus' -> AutomaticTaxStatus' -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON AutomaticTaxStatus' where
  toJSON :: AutomaticTaxStatus' -> Value
toJSON (AutomaticTaxStatus'Other Value
val) = Value
val
  toJSON (AutomaticTaxStatus'Typed Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
  toJSON (AutomaticTaxStatus'
AutomaticTaxStatus'EnumComplete) = Value
"complete"
  toJSON (AutomaticTaxStatus'
AutomaticTaxStatus'EnumFailed) = Value
"failed"
  toJSON (AutomaticTaxStatus'
AutomaticTaxStatus'EnumRequiresLocationInputs) = Value
"requires_location_inputs"

instance Data.Aeson.Types.FromJSON.FromJSON AutomaticTaxStatus' where
  parseJSON :: Value -> Parser AutomaticTaxStatus'
parseJSON Value
val =
    AutomaticTaxStatus' -> Parser AutomaticTaxStatus'
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
"complete" -> AutomaticTaxStatus'
AutomaticTaxStatus'EnumComplete
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"failed" -> AutomaticTaxStatus'
AutomaticTaxStatus'EnumFailed
            | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"requires_location_inputs" -> AutomaticTaxStatus'
AutomaticTaxStatus'EnumRequiresLocationInputs
            | Bool
GHC.Base.otherwise -> Value -> AutomaticTaxStatus'
AutomaticTaxStatus'Other Value
val
      )