{-# 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 ExternalProductReferenceBase
module RecurlyClient.Types.ExternalProductReferenceBase 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 qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | Defines the object schema located at @components.schemas.ExternalProductReferenceBase@ in the specification.
data ExternalProductReferenceBase = ExternalProductReferenceBase
    { ExternalProductReferenceBase
-> Maybe ExternalProductReferenceBaseExternal_connection_type
externalProductReferenceBaseExternal_connection_type :: (GHC.Maybe.Maybe ExternalProductReferenceBaseExternal_connection_type)
    -- ^ external_connection_type
    , ExternalProductReferenceBase -> Maybe Text
externalProductReferenceBaseReference_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 -> ExternalProductReferenceBase -> ShowS
[ExternalProductReferenceBase] -> ShowS
ExternalProductReferenceBase -> String
(Int -> ExternalProductReferenceBase -> ShowS)
-> (ExternalProductReferenceBase -> String)
-> ([ExternalProductReferenceBase] -> ShowS)
-> Show ExternalProductReferenceBase
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExternalProductReferenceBase -> ShowS
showsPrec :: Int -> ExternalProductReferenceBase -> ShowS
$cshow :: ExternalProductReferenceBase -> String
show :: ExternalProductReferenceBase -> String
$cshowList :: [ExternalProductReferenceBase] -> ShowS
showList :: [ExternalProductReferenceBase] -> ShowS
GHC.Show.Show
        , ExternalProductReferenceBase
-> ExternalProductReferenceBase -> Bool
(ExternalProductReferenceBase
 -> ExternalProductReferenceBase -> Bool)
-> (ExternalProductReferenceBase
    -> ExternalProductReferenceBase -> Bool)
-> Eq ExternalProductReferenceBase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExternalProductReferenceBase
-> ExternalProductReferenceBase -> Bool
== :: ExternalProductReferenceBase
-> ExternalProductReferenceBase -> Bool
$c/= :: ExternalProductReferenceBase
-> ExternalProductReferenceBase -> Bool
/= :: ExternalProductReferenceBase
-> ExternalProductReferenceBase -> Bool
GHC.Classes.Eq
        )

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

-- | Create a new 'ExternalProductReferenceBase' with all required fields.
mkExternalProductReferenceBase :: ExternalProductReferenceBase
mkExternalProductReferenceBase :: ExternalProductReferenceBase
mkExternalProductReferenceBase =
    ExternalProductReferenceBase
        { externalProductReferenceBaseExternal_connection_type :: Maybe ExternalProductReferenceBaseExternal_connection_type
externalProductReferenceBaseExternal_connection_type = Maybe ExternalProductReferenceBaseExternal_connection_type
forall a. Maybe a
GHC.Maybe.Nothing
        , externalProductReferenceBaseReference_code :: Maybe Text
externalProductReferenceBaseReference_code = Maybe Text
forall a. Maybe a
GHC.Maybe.Nothing
        }

-- | Defines the enum schema located at @components.schemas.ExternalProductReferenceBase.properties.external_connection_type@ in the specification.
data ExternalProductReferenceBaseExternal_connection_type
    = -- | This case is used if the value encountered during decoding does not match any of the provided cases in the specification.
      ExternalProductReferenceBaseExternal_connection_typeOther Data.Aeson.Types.Internal.Value
    | -- | This constructor can be used to send values to the server which are not present in the specification yet.
      ExternalProductReferenceBaseExternal_connection_typeTyped Data.Text.Internal.Text
    | -- | Represents the JSON value @"apple_app_store"@
      ExternalProductReferenceBaseExternal_connection_typeEnumApple_app_store
    | -- | Represents the JSON value @"google_play_store"@
      ExternalProductReferenceBaseExternal_connection_typeEnumGoogle_play_store
    deriving (Int
-> ExternalProductReferenceBaseExternal_connection_type -> ShowS
[ExternalProductReferenceBaseExternal_connection_type] -> ShowS
ExternalProductReferenceBaseExternal_connection_type -> String
(Int
 -> ExternalProductReferenceBaseExternal_connection_type -> ShowS)
-> (ExternalProductReferenceBaseExternal_connection_type -> String)
-> ([ExternalProductReferenceBaseExternal_connection_type]
    -> ShowS)
-> Show ExternalProductReferenceBaseExternal_connection_type
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int
-> ExternalProductReferenceBaseExternal_connection_type -> ShowS
showsPrec :: Int
-> ExternalProductReferenceBaseExternal_connection_type -> ShowS
$cshow :: ExternalProductReferenceBaseExternal_connection_type -> String
show :: ExternalProductReferenceBaseExternal_connection_type -> String
$cshowList :: [ExternalProductReferenceBaseExternal_connection_type] -> ShowS
showList :: [ExternalProductReferenceBaseExternal_connection_type] -> ShowS
GHC.Show.Show, ExternalProductReferenceBaseExternal_connection_type
-> ExternalProductReferenceBaseExternal_connection_type -> Bool
(ExternalProductReferenceBaseExternal_connection_type
 -> ExternalProductReferenceBaseExternal_connection_type -> Bool)
-> (ExternalProductReferenceBaseExternal_connection_type
    -> ExternalProductReferenceBaseExternal_connection_type -> Bool)
-> Eq ExternalProductReferenceBaseExternal_connection_type
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExternalProductReferenceBaseExternal_connection_type
-> ExternalProductReferenceBaseExternal_connection_type -> Bool
== :: ExternalProductReferenceBaseExternal_connection_type
-> ExternalProductReferenceBaseExternal_connection_type -> Bool
$c/= :: ExternalProductReferenceBaseExternal_connection_type
-> ExternalProductReferenceBaseExternal_connection_type -> Bool
/= :: ExternalProductReferenceBaseExternal_connection_type
-> ExternalProductReferenceBaseExternal_connection_type -> Bool
GHC.Classes.Eq)

instance Data.Aeson.Types.ToJSON.ToJSON ExternalProductReferenceBaseExternal_connection_type where
    toJSON :: ExternalProductReferenceBaseExternal_connection_type -> Value
toJSON (ExternalProductReferenceBaseExternal_connection_typeOther Value
val) = Value
val
    toJSON (ExternalProductReferenceBaseExternal_connection_typeTyped Text
val) = Text -> Value
forall a. ToJSON a => a -> Value
Data.Aeson.Types.ToJSON.toJSON Text
val
    toJSON (ExternalProductReferenceBaseExternal_connection_type
ExternalProductReferenceBaseExternal_connection_typeEnumApple_app_store) = Value
"apple_app_store"
    toJSON (ExternalProductReferenceBaseExternal_connection_type
ExternalProductReferenceBaseExternal_connection_typeEnumGoogle_play_store) = Value
"google_play_store"
instance Data.Aeson.Types.FromJSON.FromJSON ExternalProductReferenceBaseExternal_connection_type where
    parseJSON :: Value
-> Parser ExternalProductReferenceBaseExternal_connection_type
parseJSON Value
val =
        ExternalProductReferenceBaseExternal_connection_type
-> Parser ExternalProductReferenceBaseExternal_connection_type
forall a. a -> Parser a
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
"apple_app_store" -> ExternalProductReferenceBaseExternal_connection_type
ExternalProductReferenceBaseExternal_connection_typeEnumApple_app_store
                | Value
val Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Value
"google_play_store" -> ExternalProductReferenceBaseExternal_connection_type
ExternalProductReferenceBaseExternal_connection_typeEnumGoogle_play_store
                | Bool
GHC.Base.otherwise -> Value -> ExternalProductReferenceBaseExternal_connection_type
ExternalProductReferenceBaseExternal_connection_typeOther Value
val
            )