{-# 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 ExternalProductReferenceUpdate
module RecurlyClient.Types.ExternalProductReferenceUpdate 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.ExternalProductReferenceUpdate.allOf@ in the specification.
data ExternalProductReferenceUpdate = ExternalProductReferenceUpdate
    { ExternalProductReferenceUpdate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceUpdateExternal_connection_type :: (GHC.Maybe.Maybe ExternalProductReferenceConnectionType)
    -- ^ external_connection_type: Represents the connection type. One of the connection types of your enabled App Connectors
    , ExternalProductReferenceUpdate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceUpdateReference_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 -> ExternalProductReferenceUpdate -> ShowS
[ExternalProductReferenceUpdate] -> ShowS
ExternalProductReferenceUpdate -> String
(Int -> ExternalProductReferenceUpdate -> ShowS)
-> (ExternalProductReferenceUpdate -> String)
-> ([ExternalProductReferenceUpdate] -> ShowS)
-> Show ExternalProductReferenceUpdate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExternalProductReferenceUpdate -> ShowS
showsPrec :: Int -> ExternalProductReferenceUpdate -> ShowS
$cshow :: ExternalProductReferenceUpdate -> String
show :: ExternalProductReferenceUpdate -> String
$cshowList :: [ExternalProductReferenceUpdate] -> ShowS
showList :: [ExternalProductReferenceUpdate] -> ShowS
GHC.Show.Show
        , ExternalProductReferenceUpdate
-> ExternalProductReferenceUpdate -> Bool
(ExternalProductReferenceUpdate
 -> ExternalProductReferenceUpdate -> Bool)
-> (ExternalProductReferenceUpdate
    -> ExternalProductReferenceUpdate -> Bool)
-> Eq ExternalProductReferenceUpdate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExternalProductReferenceUpdate
-> ExternalProductReferenceUpdate -> Bool
== :: ExternalProductReferenceUpdate
-> ExternalProductReferenceUpdate -> Bool
$c/= :: ExternalProductReferenceUpdate
-> ExternalProductReferenceUpdate -> Bool
/= :: ExternalProductReferenceUpdate
-> ExternalProductReferenceUpdate -> Bool
GHC.Classes.Eq
        )

instance Data.Aeson.Types.ToJSON.ToJSON ExternalProductReferenceUpdate where
    toJSON :: ExternalProductReferenceUpdate -> Value
toJSON ExternalProductReferenceUpdate
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..=)) (ExternalProductReferenceUpdate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceUpdateExternal_connection_type ExternalProductReferenceUpdate
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..=)) (ExternalProductReferenceUpdate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceUpdateReference_code ExternalProductReferenceUpdate
obj) [Pair] -> [[Pair]] -> [[Pair]]
forall a. a -> [a] -> [a]
: [[Pair]]
forall a. Monoid a => a
GHC.Base.mempty))
    toEncoding :: ExternalProductReferenceUpdate -> Encoding
toEncoding ExternalProductReferenceUpdate
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..=)) (ExternalProductReferenceUpdate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceUpdateExternal_connection_type ExternalProductReferenceUpdate
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..=)) (ExternalProductReferenceUpdate
-> Maybe ExternalProductReferenceConnectionType
externalProductReferenceUpdateReference_code ExternalProductReferenceUpdate
obj) [Series] -> [[Series]] -> [[Series]]
forall a. a -> [a] -> [a]
: [[Series]]
forall a. Monoid a => a
GHC.Base.mempty)))
instance Data.Aeson.Types.FromJSON.FromJSON ExternalProductReferenceUpdate where
    parseJSON :: Value -> Parser ExternalProductReferenceUpdate
parseJSON = String
-> (Object -> Parser ExternalProductReferenceUpdate)
-> Value
-> Parser ExternalProductReferenceUpdate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"ExternalProductReferenceUpdate" (\Object
obj -> ((Maybe ExternalProductReferenceConnectionType
 -> Maybe ExternalProductReferenceConnectionType
 -> ExternalProductReferenceUpdate)
-> Parser
     (Maybe ExternalProductReferenceConnectionType
      -> Maybe ExternalProductReferenceConnectionType
      -> ExternalProductReferenceUpdate)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Maybe ExternalProductReferenceConnectionType
-> Maybe ExternalProductReferenceConnectionType
-> ExternalProductReferenceUpdate
ExternalProductReferenceUpdate Parser
  (Maybe ExternalProductReferenceConnectionType
   -> Maybe ExternalProductReferenceConnectionType
   -> ExternalProductReferenceUpdate)
-> Parser (Maybe ExternalProductReferenceConnectionType)
-> Parser
     (Maybe ExternalProductReferenceConnectionType
      -> ExternalProductReferenceUpdate)
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
   -> ExternalProductReferenceUpdate)
-> Parser (Maybe ExternalProductReferenceConnectionType)
-> Parser ExternalProductReferenceUpdate
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 'ExternalProductReferenceUpdate' with all required fields.
mkExternalProductReferenceUpdate :: ExternalProductReferenceUpdate
mkExternalProductReferenceUpdate :: ExternalProductReferenceUpdate
mkExternalProductReferenceUpdate =
    ExternalProductReferenceUpdate
        { externalProductReferenceUpdateExternal_connection_type :: Maybe ExternalProductReferenceConnectionType
externalProductReferenceUpdateExternal_connection_type = Maybe ExternalProductReferenceConnectionType
forall a. Maybe a
GHC.Maybe.Nothing
        , externalProductReferenceUpdateReference_code :: Maybe ExternalProductReferenceConnectionType
externalProductReferenceUpdateReference_code = Maybe ExternalProductReferenceConnectionType
forall a. Maybe a
GHC.Maybe.Nothing
        }