{-# 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 ExternalProductReferenceCreate
module RecurlyClient.Types.ExternalProductReferenceCreate 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.ExternalProductReferenceCreate.allOf@ in the specification.
data ExternalProductReferenceCreate = ExternalProductReferenceCreate
    { ExternalProductReferenceCreate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceCreateExternal_connection_type :: (GHC.Maybe.Maybe ExternalProductReferenceConnectionType)
    -- ^ external_connection_type: Represents the connection type. One of the connection types of your enabled App Connectors
    , ExternalProductReferenceCreate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceCreateReference_code :: (GHC.Maybe.Maybe Data.Text.Internal.Text)
    -- ^ reference_code: A code which associates the external product to a corresponding object or resource in an external platform like the Apple App Store or Google Play Store.
    --
    -- Constraints:
    --
    -- * Maximum length of 255
    }
    deriving
        ( Int -> ExternalProductReferenceCreate -> ShowS
[ExternalProductReferenceCreate] -> ShowS
ExternalProductReferenceCreate -> String
(Int -> ExternalProductReferenceCreate -> ShowS)
-> (ExternalProductReferenceCreate -> String)
-> ([ExternalProductReferenceCreate] -> ShowS)
-> Show ExternalProductReferenceCreate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExternalProductReferenceCreate -> ShowS
showsPrec :: Int -> ExternalProductReferenceCreate -> ShowS
$cshow :: ExternalProductReferenceCreate -> String
show :: ExternalProductReferenceCreate -> String
$cshowList :: [ExternalProductReferenceCreate] -> ShowS
showList :: [ExternalProductReferenceCreate] -> ShowS
GHC.Show.Show
        , ExternalProductReferenceCreate
-> ExternalProductReferenceCreate -> Bool
(ExternalProductReferenceCreate
 -> ExternalProductReferenceCreate -> Bool)
-> (ExternalProductReferenceCreate
    -> ExternalProductReferenceCreate -> Bool)
-> Eq ExternalProductReferenceCreate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExternalProductReferenceCreate
-> ExternalProductReferenceCreate -> Bool
== :: ExternalProductReferenceCreate
-> ExternalProductReferenceCreate -> Bool
$c/= :: ExternalProductReferenceCreate
-> ExternalProductReferenceCreate -> Bool
/= :: ExternalProductReferenceCreate
-> ExternalProductReferenceCreate -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON ExternalProductReferenceCreate where
    toJSON :: ExternalProductReferenceCreate -> Value
toJSON ExternalProductReferenceCreate
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object ([[Pair]] -> [Pair]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
Data.Foldable.concat ([Pair]
-> (ExternalProductReferenceConnectionType -> [Pair])
-> Maybe ExternalProductReferenceConnectionType
-> [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])
-> (ExternalProductReferenceConnectionType -> Pair)
-> ExternalProductReferenceConnectionType
-> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"external_connection_type" Key -> ExternalProductReferenceConnectionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (ExternalProductReferenceCreate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceCreateExternal_connection_type ExternalProductReferenceCreate
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [Pair]
-> (ExternalProductReferenceConnectionType -> [Pair])
-> Maybe ExternalProductReferenceConnectionType
-> [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])
-> (ExternalProductReferenceConnectionType -> Pair)
-> ExternalProductReferenceConnectionType
-> [Pair]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"reference_code" Key -> ExternalProductReferenceConnectionType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Data.Aeson.Types.ToJSON..=)) (ExternalProductReferenceCreate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceCreateReference_code ExternalProductReferenceCreate
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: ExternalProductReferenceCreate -> Encoding
toEncoding ExternalProductReferenceCreate
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]
-> (ExternalProductReferenceConnectionType -> [Series])
-> Maybe ExternalProductReferenceConnectionType
-> [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])
-> (ExternalProductReferenceConnectionType -> Series)
-> ExternalProductReferenceConnectionType
-> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"external_connection_type" Key -> ExternalProductReferenceConnectionType -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (ExternalProductReferenceCreate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceCreateExternal_connection_type ExternalProductReferenceCreate
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [Series]
-> (ExternalProductReferenceConnectionType -> [Series])
-> Maybe ExternalProductReferenceConnectionType
-> [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])
-> (ExternalProductReferenceConnectionType -> Series)
-> ExternalProductReferenceConnectionType
-> [Series]
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. (Key
"reference_code" Key -> ExternalProductReferenceConnectionType -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Data.Aeson.Types.ToJSON..=)) (ExternalProductReferenceCreate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceCreateReference_code ExternalProductReferenceCreate
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON ExternalProductReferenceCreate where
    parseJSON :: Value -> Parser ExternalProductReferenceCreate
parseJSON = String
-> (Object -> Parser ExternalProductReferenceCreate)
-> Value
-> Parser ExternalProductReferenceCreate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"ExternalProductReferenceCreate" (\Object
obj -> ((Maybe ExternalProductReferenceConnectionType
 -> Maybe ExternalProductReferenceConnectionType
 -> ExternalProductReferenceCreate)
-> Parser
     (Maybe ExternalProductReferenceConnectionType
      -> Maybe ExternalProductReferenceConnectionType
      -> ExternalProductReferenceCreate)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe ExternalProductReferenceConnectionType
-> Maybe ExternalProductReferenceConnectionType
-> ExternalProductReferenceCreate
ExternalProductReferenceCreate Parser
  (Maybe ExternalProductReferenceConnectionType
   -> Maybe ExternalProductReferenceConnectionType
   -> ExternalProductReferenceCreate)
-> Parser (Maybe ExternalProductReferenceConnectionType)
-> Parser
     (Maybe ExternalProductReferenceConnectionType
      -> ExternalProductReferenceCreate)
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 ExternalProductReferenceConnectionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"external_connection_type")) Parser
  (Maybe ExternalProductReferenceConnectionType
   -> ExternalProductReferenceCreate)
-> Parser (Maybe ExternalProductReferenceConnectionType)
-> Parser ExternalProductReferenceCreate
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 ExternalProductReferenceConnectionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data.Aeson.Types.FromJSON..:? Key
"reference_code"))

-- | Create a new 'ExternalProductReferenceCreate' with all required fields.
mkExternalProductReferenceCreate :: ExternalProductReferenceCreate
mkExternalProductReferenceCreate :: ExternalProductReferenceCreate
mkExternalProductReferenceCreate =
    ExternalProductReferenceCreate
        { externalProductReferenceCreateExternal_connection_type :: Maybe ExternalProductReferenceConnectionType
externalProductReferenceCreateExternal_connection_type = Maybe ExternalProductReferenceConnectionType
forall a. Maybe a
GHC.Maybe.Nothing
        , externalProductReferenceCreateReference_code :: Maybe ExternalProductReferenceConnectionType
externalProductReferenceCreateReference_code = Maybe ExternalProductReferenceConnectionType
forall a. Maybe a
GHC.Maybe.Nothing
        }