{-# LANGUAGE ExplicitForAll #-}
{-# 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 different functions to run the operation postApplePayDomains
module StripeAPI.Operations.PostApplePayDomains where

import qualified Control.Monad.Fail
import qualified Control.Monad.Trans.Reader
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.Either
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 Data.Vector
import qualified GHC.Base
import qualified GHC.Classes
import qualified GHC.Int
import qualified GHC.Show
import qualified GHC.Types
import qualified Network.HTTP.Client
import qualified Network.HTTP.Client as Network.HTTP.Client.Request
import qualified Network.HTTP.Client as Network.HTTP.Client.Types
import qualified Network.HTTP.Simple
import qualified Network.HTTP.Types
import qualified Network.HTTP.Types as Network.HTTP.Types.Status
import qualified Network.HTTP.Types as Network.HTTP.Types.URI
import qualified StripeAPI.Common
import StripeAPI.Types
import qualified Prelude as GHC.Integer.Type
import qualified Prelude as GHC.Maybe

-- | > POST /v1/apple_pay/domains
--
-- \<p>Create an apple pay domain.\<\/p>
postApplePayDomains ::
  forall m.
  StripeAPI.Common.MonadHTTP m =>
  -- | The request body to send
  PostApplePayDomainsRequestBody ->
  -- | Monadic computation which returns the result of the operation
  StripeAPI.Common.ClientT m (Network.HTTP.Client.Types.Response PostApplePayDomainsResponse)
postApplePayDomains :: PostApplePayDomainsRequestBody
-> ClientT m (Response PostApplePayDomainsResponse)
postApplePayDomains PostApplePayDomainsRequestBody
body =
  (Response ByteString -> Response PostApplePayDomainsResponse)
-> ClientT m (Response ByteString)
-> ClientT m (Response PostApplePayDomainsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
    ( \Response ByteString
response_0 ->
        (ByteString -> PostApplePayDomainsResponse)
-> Response ByteString -> Response PostApplePayDomainsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
GHC.Base.fmap
          ( (String -> PostApplePayDomainsResponse)
-> (PostApplePayDomainsResponse -> PostApplePayDomainsResponse)
-> Either String PostApplePayDomainsResponse
-> PostApplePayDomainsResponse
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
Data.Either.either String -> PostApplePayDomainsResponse
PostApplePayDomainsResponseError PostApplePayDomainsResponse -> PostApplePayDomainsResponse
forall a. a -> a
GHC.Base.id
              (Either String PostApplePayDomainsResponse
 -> PostApplePayDomainsResponse)
-> (ByteString -> Either String PostApplePayDomainsResponse)
-> ByteString
-> PostApplePayDomainsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
GHC.Base.. ( \Response ByteString
response ByteString
body ->
                             if
                                 | (\Status
status_1 -> Status -> Int
Network.HTTP.Types.Status.statusCode Status
status_1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
GHC.Classes.== Int
200) (Response ByteString -> Status
forall body. Response body -> Status
Network.HTTP.Client.Types.responseStatus Response ByteString
response) ->
                                   ApplePayDomain -> PostApplePayDomainsResponse
PostApplePayDomainsResponse200
                                     (ApplePayDomain -> PostApplePayDomainsResponse)
-> Either String ApplePayDomain
-> Either String PostApplePayDomainsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> ( ByteString -> Either String ApplePayDomain
forall a. FromJSON a => ByteString -> Either String a
Data.Aeson.eitherDecodeStrict ByteString
body ::
                                                          Data.Either.Either
                                                            GHC.Base.String
                                                            ApplePayDomain
                                                      )
                                 | Bool -> Status -> Bool
forall a b. a -> b -> a
GHC.Base.const Bool
GHC.Types.True (Response ByteString -> Status
forall body. Response body -> Status
Network.HTTP.Client.Types.responseStatus Response ByteString
response) ->
                                   Error -> PostApplePayDomainsResponse
PostApplePayDomainsResponseDefault
                                     (Error -> PostApplePayDomainsResponse)
-> Either String Error -> Either String PostApplePayDomainsResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Data.Functor.<$> ( ByteString -> Either String Error
forall a. FromJSON a => ByteString -> Either String a
Data.Aeson.eitherDecodeStrict ByteString
body ::
                                                          Data.Either.Either
                                                            GHC.Base.String
                                                            Error
                                                      )
                                 | Bool
GHC.Base.otherwise -> String -> Either String PostApplePayDomainsResponse
forall a b. a -> Either a b
Data.Either.Left String
"Missing default response type"
                         )
                Response ByteString
response_0
          )
          Response ByteString
response_0
    )
    (Text
-> Text
-> [QueryParameter]
-> Maybe PostApplePayDomainsRequestBody
-> RequestBodyEncoding
-> ClientT m (Response ByteString)
forall (m :: * -> *) body.
(MonadHTTP m, ToJSON body) =>
Text
-> Text
-> [QueryParameter]
-> Maybe body
-> RequestBodyEncoding
-> ClientT m (Response ByteString)
StripeAPI.Common.doBodyCallWithConfigurationM (Text -> Text
Data.Text.toUpper (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
GHC.Base.$ String -> Text
Data.Text.pack String
"POST") (String -> Text
Data.Text.pack String
"/v1/apple_pay/domains") [QueryParameter]
forall a. Monoid a => a
GHC.Base.mempty (PostApplePayDomainsRequestBody
-> Maybe PostApplePayDomainsRequestBody
forall a. a -> Maybe a
GHC.Maybe.Just PostApplePayDomainsRequestBody
body) RequestBodyEncoding
StripeAPI.Common.RequestBodyEncodingFormData)

-- | Defines the object schema located at @paths.\/v1\/apple_pay\/domains.POST.requestBody.content.application\/x-www-form-urlencoded.schema@ in the specification.
data PostApplePayDomainsRequestBody = PostApplePayDomainsRequestBody
  { -- | domain_name
    PostApplePayDomainsRequestBody -> Text
postApplePayDomainsRequestBodyDomainName :: Data.Text.Internal.Text,
    -- | expand: Specifies which fields in the response should be expanded.
    PostApplePayDomainsRequestBody -> Maybe [Text]
postApplePayDomainsRequestBodyExpand :: (GHC.Maybe.Maybe ([Data.Text.Internal.Text]))
  }
  deriving
    ( Int -> PostApplePayDomainsRequestBody -> ShowS
[PostApplePayDomainsRequestBody] -> ShowS
PostApplePayDomainsRequestBody -> String
(Int -> PostApplePayDomainsRequestBody -> ShowS)
-> (PostApplePayDomainsRequestBody -> String)
-> ([PostApplePayDomainsRequestBody] -> ShowS)
-> Show PostApplePayDomainsRequestBody
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PostApplePayDomainsRequestBody] -> ShowS
$cshowList :: [PostApplePayDomainsRequestBody] -> ShowS
show :: PostApplePayDomainsRequestBody -> String
$cshow :: PostApplePayDomainsRequestBody -> String
showsPrec :: Int -> PostApplePayDomainsRequestBody -> ShowS
$cshowsPrec :: Int -> PostApplePayDomainsRequestBody -> ShowS
GHC.Show.Show,
      PostApplePayDomainsRequestBody
-> PostApplePayDomainsRequestBody -> Bool
(PostApplePayDomainsRequestBody
 -> PostApplePayDomainsRequestBody -> Bool)
-> (PostApplePayDomainsRequestBody
    -> PostApplePayDomainsRequestBody -> Bool)
-> Eq PostApplePayDomainsRequestBody
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostApplePayDomainsRequestBody
-> PostApplePayDomainsRequestBody -> Bool
$c/= :: PostApplePayDomainsRequestBody
-> PostApplePayDomainsRequestBody -> Bool
== :: PostApplePayDomainsRequestBody
-> PostApplePayDomainsRequestBody -> Bool
$c== :: PostApplePayDomainsRequestBody
-> PostApplePayDomainsRequestBody -> Bool
GHC.Classes.Eq
    )

instance Data.Aeson.Types.ToJSON.ToJSON PostApplePayDomainsRequestBody where
  toJSON :: PostApplePayDomainsRequestBody -> Value
toJSON PostApplePayDomainsRequestBody
obj = [Pair] -> Value
Data.Aeson.Types.Internal.object (Text
"domain_name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostApplePayDomainsRequestBody -> Text
postApplePayDomainsRequestBodyDomainName PostApplePayDomainsRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: Text
"expand" Text -> Maybe [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostApplePayDomainsRequestBody -> Maybe [Text]
postApplePayDomainsRequestBodyExpand PostApplePayDomainsRequestBody
obj Pair -> [Pair] -> [Pair]
forall a. a -> [a] -> [a]
: [Pair]
forall a. Monoid a => a
GHC.Base.mempty)
  toEncoding :: PostApplePayDomainsRequestBody -> Encoding
toEncoding PostApplePayDomainsRequestBody
obj = Series -> Encoding
Data.Aeson.Encoding.Internal.pairs ((Text
"domain_name" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostApplePayDomainsRequestBody -> Text
postApplePayDomainsRequestBodyDomainName PostApplePayDomainsRequestBody
obj) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
GHC.Base.<> (Text
"expand" Text -> Maybe [Text] -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Data.Aeson.Types.ToJSON..= PostApplePayDomainsRequestBody -> Maybe [Text]
postApplePayDomainsRequestBodyExpand PostApplePayDomainsRequestBody
obj))

instance Data.Aeson.Types.FromJSON.FromJSON PostApplePayDomainsRequestBody where
  parseJSON :: Value -> Parser PostApplePayDomainsRequestBody
parseJSON = String
-> (Object -> Parser PostApplePayDomainsRequestBody)
-> Value
-> Parser PostApplePayDomainsRequestBody
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.Aeson.Types.FromJSON.withObject String
"PostApplePayDomainsRequestBody" (\Object
obj -> ((Text -> Maybe [Text] -> PostApplePayDomainsRequestBody)
-> Parser (Text -> Maybe [Text] -> PostApplePayDomainsRequestBody)
forall (f :: * -> *) a. Applicative f => a -> f a
GHC.Base.pure Text -> Maybe [Text] -> PostApplePayDomainsRequestBody
PostApplePayDomainsRequestBody Parser (Text -> Maybe [Text] -> PostApplePayDomainsRequestBody)
-> Parser Text
-> Parser (Maybe [Text] -> PostApplePayDomainsRequestBody)
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
"domain_name")) Parser (Maybe [Text] -> PostApplePayDomainsRequestBody)
-> Parser (Maybe [Text]) -> Parser PostApplePayDomainsRequestBody
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
"expand"))

-- | Create a new 'PostApplePayDomainsRequestBody' with all required fields.
mkPostApplePayDomainsRequestBody ::
  -- | 'postApplePayDomainsRequestBodyDomainName'
  Data.Text.Internal.Text ->
  PostApplePayDomainsRequestBody
mkPostApplePayDomainsRequestBody :: Text -> PostApplePayDomainsRequestBody
mkPostApplePayDomainsRequestBody Text
postApplePayDomainsRequestBodyDomainName =
  PostApplePayDomainsRequestBody :: Text -> Maybe [Text] -> PostApplePayDomainsRequestBody
PostApplePayDomainsRequestBody
    { postApplePayDomainsRequestBodyDomainName :: Text
postApplePayDomainsRequestBodyDomainName = Text
postApplePayDomainsRequestBodyDomainName,
      postApplePayDomainsRequestBodyExpand :: Maybe [Text]
postApplePayDomainsRequestBodyExpand = Maybe [Text]
forall a. Maybe a
GHC.Maybe.Nothing
    }

-- | Represents a response of the operation 'postApplePayDomains'.
--
-- The response constructor is chosen by the status code of the response. If no case matches (no specific case for the response code, no range case, no default case), 'PostApplePayDomainsResponseError' is used.
data PostApplePayDomainsResponse
  = -- | Means either no matching case available or a parse error
    PostApplePayDomainsResponseError GHC.Base.String
  | -- | Successful response.
    PostApplePayDomainsResponse200 ApplePayDomain
  | -- | Error response.
    PostApplePayDomainsResponseDefault Error
  deriving (Int -> PostApplePayDomainsResponse -> ShowS
[PostApplePayDomainsResponse] -> ShowS
PostApplePayDomainsResponse -> String
(Int -> PostApplePayDomainsResponse -> ShowS)
-> (PostApplePayDomainsResponse -> String)
-> ([PostApplePayDomainsResponse] -> ShowS)
-> Show PostApplePayDomainsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PostApplePayDomainsResponse] -> ShowS
$cshowList :: [PostApplePayDomainsResponse] -> ShowS
show :: PostApplePayDomainsResponse -> String
$cshow :: PostApplePayDomainsResponse -> String
showsPrec :: Int -> PostApplePayDomainsResponse -> ShowS
$cshowsPrec :: Int -> PostApplePayDomainsResponse -> ShowS
GHC.Show.Show, PostApplePayDomainsResponse -> PostApplePayDomainsResponse -> Bool
(PostApplePayDomainsResponse
 -> PostApplePayDomainsResponse -> Bool)
-> (PostApplePayDomainsResponse
    -> PostApplePayDomainsResponse -> Bool)
-> Eq PostApplePayDomainsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PostApplePayDomainsResponse -> PostApplePayDomainsResponse -> Bool
$c/= :: PostApplePayDomainsResponse -> PostApplePayDomainsResponse -> Bool
== :: PostApplePayDomainsResponse -> PostApplePayDomainsResponse -> Bool
$c== :: PostApplePayDomainsResponse -> PostApplePayDomainsResponse -> Bool
GHC.Classes.Eq)