{-# 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 ExternalProductCreate
module RecurlyClient.Types.ExternalProductCreate 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
import qualified Data.ByteString as Data.ByteString.Internal
import qualified Data.Foldable
import qualified Data.Functor
import qualified Data.Maybe
import qualified Data.Scientific
import qualified Data.Text
import qualified Data.Text as 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 RecurlyClient.Common
import RecurlyClient.TypeAlias
import {-# SOURCE #-} RecurlyClient.Types.ExternalProductReferenceBase
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.ExternalProductCreate@ in the specification.
data ExternalProductCreate = ExternalProductCreate
    { ExternalProductCreate -> Maybe [ExternalProductReferenceBase]
externalProductCreateExternal_product_references :: (GHC.Maybe.Maybe [ExternalProductReferenceBase])
    -- ^ external_product_references: List of external product references of the external product.
    , ExternalProductCreate -> Text
externalProductCreateName :: Data.Text.Internal.Text
    -- ^ name: External product name.
    , ExternalProductCreate -> Maybe Text
externalProductCreatePlan_id :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
    -- ^ plan_id: Recurly plan UUID.
    }
    deriving
        ( Int -> ExternalProductCreate -> ShowS
[ExternalProductCreate] -> ShowS
ExternalProductCreate -> String
(Int -> ExternalProductCreate -> ShowS)
-> (ExternalProductCreate -> String)
-> ([ExternalProductCreate] -> ShowS)
-> Show ExternalProductCreate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExternalProductCreate -> ShowS
showsPrec :: Int -> ExternalProductCreate -> ShowS
$cshow :: ExternalProductCreate -> String
show :: ExternalProductCreate -> String
$cshowList :: [ExternalProductCreate] -> ShowS
showList :: [ExternalProductCreate] -> ShowS
GHC.Show.Show
        , ExternalProductCreate -> ExternalProductCreate -> Bool
(ExternalProductCreate -> ExternalProductCreate -> Bool)
-> (ExternalProductCreate -> ExternalProductCreate -> Bool)
-> Eq ExternalProductCreate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExternalProductCreate -> ExternalProductCreate -> Bool
== :: ExternalProductCreate -> ExternalProductCreate -> Bool
$c/= :: ExternalProductCreate -> ExternalProductCreate -> Bool
/= :: ExternalProductCreate -> ExternalProductCreate -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON ExternalProductCreate where
    toJSON :: ExternalProductCreate -> Value
toJSON ExternalProductCreate
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Pair]
-> ([ExternalProductReferenceBase] -> [Pair])
-> Maybe [ExternalProductReferenceBase]
-> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair])
-> ([ExternalProductReferenceBase] -> Pair)
-> [ExternalProductReferenceBase]
-> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"external_product_references" Key -> [ExternalProductReferenceBase] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (ExternalProductCreate -> Maybe [ExternalProductReferenceBase]
externalProductCreateExternal_product_references ExternalProductCreate
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Key
"name" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..= ExternalProductCreate -> Text
externalProductCreateName ExternalProductCreate
obj] [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair] -> (Text -> [Pair]) -> Maybe Text -> [Pair]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Pair]
forall a. Monoid a => a
GHC.Base.mempty (Pair -> [Pair]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Pair -> [Pair]) -> (Text -> Pair) -> Text -> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"plan_id" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (ExternalProductCreate -> Maybe Text
externalProductCreatePlan_id ExternalProductCreate
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: ExternalProductCreate -> Encoding
toEncoding ExternalProductCreate
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ([Series] -> Series
forall a. Monoid a => [a] -> a
GHC.Base.mconcat ([[Series]] -> [Series]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Series]
-> ([ExternalProductReferenceBase] -> [Series])
-> Maybe [ExternalProductReferenceBase]
-> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series])
-> ([ExternalProductReferenceBase] -> Series)
-> [ExternalProductReferenceBase]
-> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"external_product_references" Key -> [ExternalProductReferenceBase] -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (ExternalProductCreate -> Maybe [ExternalProductReferenceBase]
externalProductCreateExternal_product_references ExternalProductCreate
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Key
"name" Key -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..= ExternalProductCreate -> Text
externalProductCreateName ExternalProductCreate
obj] [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series] -> (Text -> [Series]) -> Maybe Text -> [Series]
forall b a. b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybe [Series]
forall a. Monoid a => a
GHC.Base.mempty (Series -> [Series]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure (Series -> [Series]) -> (Text -> Series) -> Text -> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"plan_id" Key -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (ExternalProductCreate -> Maybe Text
externalProductCreatePlan_id ExternalProductCreate
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON ExternalProductCreate where
    parseJSON :: Value -> Parser ExternalProductCreate
parseJSON = String
-> (Object -> Parser ExternalProductCreate)
-> Value
-> Parser ExternalProductCreate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"ExternalProductCreate" (\Object
obj -> (((Maybe [ExternalProductReferenceBase]
 -> Text -> Maybe Text -> ExternalProductCreate)
-> Parser
     (Maybe [ExternalProductReferenceBase]
      -> Text -> Maybe Text -> ExternalProductCreate)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe [ExternalProductReferenceBase]
-> Text -> Maybe Text -> ExternalProductCreate
ExternalProductCreate Parser
  (Maybe [ExternalProductReferenceBase]
   -> Text -> Maybe Text -> ExternalProductCreate)
-> Parser (Maybe [ExternalProductReferenceBase])
-> Parser (Text -> Maybe Text -> ExternalProductCreate)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe [ExternalProductReferenceBase])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"external_product_references")) Parser (Text -> Maybe Text -> ExternalProductCreate)
-> Parser Text -> Parser (Maybe Text -> ExternalProductCreate)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
Data.Aeson.Types.FromJSON..: Key
"name")) Parser (Maybe Text -> ExternalProductCreate)
-> Parser (Maybe Text) -> Parser ExternalProductCreate
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
GHC.Base.<*> (Object
obj Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"plan_id"))

-- | Create a new 'ExternalProductCreate' with all required fields.
mkExternalProductCreate ::
    -- | 'externalProductCreateName'
    Data.Text.Internal.Text ->
    ExternalProductCreate
mkExternalProductCreate :: Text -> ExternalProductCreate
mkExternalProductCreate Text
externalProductCreateName =
    ExternalProductCreate
        { externalProductCreateExternal_product_references :: Maybe [ExternalProductReferenceBase]
externalProductCreateExternal_product_references = Maybe [ExternalProductReferenceBase]
forall a. Maybe a
GHC.Maybe.Nothing
        , externalProductCreateName :: Text
externalProductCreateName = Text
externalProductCreateName
        , externalProductCreatePlan_id :: Maybe Text
externalProductCreatePlan_id = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
        }