{-# 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 SkuInventory
module StripeAPI.Types.SkuInventory 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.sku_inventory@ in the specification.
data SkuInventory = SkuInventory
  { -- | quantity: The count of inventory available. Will be present if and only if \`type\` is \`finite\`.
    SkuInventory -> Maybe Int
skuInventoryQuantity :: (GHC.Maybe.Maybe GHC.Types.Int),
    -- | type: Inventory type. Possible values are \`finite\`, \`bucket\` (not quantified), and \`infinite\`.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    SkuInventory -> Text
skuInventoryType :: Data.Text.Internal.Text,
    -- | value: An indicator of the inventory available. Possible values are \`in_stock\`, \`limited\`, and \`out_of_stock\`. Will be present if and only if \`type\` is \`bucket\`.
    --
    -- Constraints:
    --
    -- * Maximum length of 5000
    SkuInventory -> Maybe Text
skuInventoryValue :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
  }
  deriving
    ( Int -> SkuInventory -> ShowS
[SkuInventory] -> ShowS
SkuInventory -> String
(Int -> SkuInventory -> ShowS)
-> (SkuInventory -> String)
-> ([SkuInventory] -> ShowS)
-> Show SkuInventory
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SkuInventory] -> ShowS
$cshowList :: [SkuInventory] -> ShowS
show :: SkuInventory -> String
$cshow :: SkuInventory -> String
showsPrec :: Int -> SkuInventory -> ShowS
$cshowsPrec :: Int -> SkuInventory -> ShowS
GHC.Show.Show,
      SkuInventory -> SkuInventory -> Bool
(SkuInventory -> SkuInventory -> Bool)
-> (SkuInventory -> SkuInventory -> Bool) -> Eq SkuInventory
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SkuInventory -> SkuInventory -> Bool
$c/= :: SkuInventory -> SkuInventory -> Bool
== :: SkuInventory -> SkuInventory -> Bool
$c== :: SkuInventory -> SkuInventory -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON SkuInventory where
  toJSON :: SkuInventory -> Value
toJSON SkuInventory
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"quantity" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SkuInventory -> Maybe Int
skuInventoryQuantity SkuInventory
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"type" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SkuInventory -> Text
skuInventoryType SkuInventory
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"value" Text -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SkuInventory -> Maybe Text
skuInventoryValue SkuInventory
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: SkuInventory -> Encoding
toEncoding SkuInventory
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"quantity" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SkuInventory -> Maybe Int
skuInventoryQuantity SkuInventory
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> ((Text
"type" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SkuInventory -> Text
skuInventoryType SkuInventory
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"value" Text -> Maybe Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= SkuInventory -> Maybe Text
skuInventoryValue SkuInventory
obj)))

instance Data.Aeson.Types.FromJSON.FromJSON SkuInventory where
  parseJSON :: Value -> Parser SkuInventory
parseJSON = String
-> (Object -> Parser SkuInventory) -> Value -> Parser SkuInventory
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"SkuInventory" (\Object
obj -> (((Maybe Int -> Text -> Maybe Text -> SkuInventory)
-> Parser (Maybe Int -> Text -> Maybe Text -> SkuInventory)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe Int -> Text -> Maybe Text -> SkuInventory
SkuInventory Parser (Maybe Int -> Text -> Maybe Text -> SkuInventory)
-> Parser (Maybe Int)
-> Parser (Text -> Maybe Text -> SkuInventory)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"quantity")) Parser (Text -> Maybe Text -> SkuInventory)
-> Parser Text -> Parser (Maybe Text -> SkuInventory)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Data.Aeson.Types.FromJSON..: Text
"type")) Parser (Maybe Text -> SkuInventory)
-> Parser (Maybe Text) -> Parser SkuInventory
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Text
"value"))

-- | Create a new 'SkuInventory' with all required fields.
mkSkuInventory ::
  -- | 'skuInventoryType'
  Data.Text.Internal.Text ->
  SkuInventory
mkSkuInventory :: Text -> SkuInventory
mkSkuInventory Text
skuInventoryType =
  SkuInventory :: Maybe Int -> Text -> Maybe Text -> SkuInventory
SkuInventory
    { skuInventoryQuantity :: Maybe Int
skuInventoryQuantity = Maybe Int
forall a. Maybe a
GHC.Maybe.Nothing,
      skuInventoryType :: Text
skuInventoryType = Text
skuInventoryType,
      skuInventoryValue :: Maybe Text
skuInventoryValue = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
    }