{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.AppSync.CreateType
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a @Type@ object.
module Amazonka.AppSync.CreateType
  ( -- * Creating a Request
    CreateType (..),
    newCreateType,

    -- * Request Lenses
    createType_apiId,
    createType_definition,
    createType_format,

    -- * Destructuring the Response
    CreateTypeResponse (..),
    newCreateTypeResponse,

    -- * Response Lenses
    createTypeResponse_type,
    createTypeResponse_httpStatus,
  )
where

import Amazonka.AppSync.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateType' smart constructor.
data CreateType = CreateType'
  { -- | The API ID.
    CreateType -> Text
apiId :: Prelude.Text,
    -- | The type definition, in GraphQL Schema Definition Language (SDL) format.
    --
    -- For more information, see the
    -- <http://graphql.org/learn/schema/ GraphQL SDL documentation>.
    CreateType -> Text
definition :: Prelude.Text,
    -- | The type format: SDL or JSON.
    CreateType -> TypeDefinitionFormat
format :: TypeDefinitionFormat
  }
  deriving (CreateType -> CreateType -> Bool
(CreateType -> CreateType -> Bool)
-> (CreateType -> CreateType -> Bool) -> Eq CreateType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateType -> CreateType -> Bool
$c/= :: CreateType -> CreateType -> Bool
== :: CreateType -> CreateType -> Bool
$c== :: CreateType -> CreateType -> Bool
Prelude.Eq, ReadPrec [CreateType]
ReadPrec CreateType
Int -> ReadS CreateType
ReadS [CreateType]
(Int -> ReadS CreateType)
-> ReadS [CreateType]
-> ReadPrec CreateType
-> ReadPrec [CreateType]
-> Read CreateType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateType]
$creadListPrec :: ReadPrec [CreateType]
readPrec :: ReadPrec CreateType
$creadPrec :: ReadPrec CreateType
readList :: ReadS [CreateType]
$creadList :: ReadS [CreateType]
readsPrec :: Int -> ReadS CreateType
$creadsPrec :: Int -> ReadS CreateType
Prelude.Read, Int -> CreateType -> ShowS
[CreateType] -> ShowS
CreateType -> String
(Int -> CreateType -> ShowS)
-> (CreateType -> String)
-> ([CreateType] -> ShowS)
-> Show CreateType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateType] -> ShowS
$cshowList :: [CreateType] -> ShowS
show :: CreateType -> String
$cshow :: CreateType -> String
showsPrec :: Int -> CreateType -> ShowS
$cshowsPrec :: Int -> CreateType -> ShowS
Prelude.Show, (forall x. CreateType -> Rep CreateType x)
-> (forall x. Rep CreateType x -> CreateType) -> Generic CreateType
forall x. Rep CreateType x -> CreateType
forall x. CreateType -> Rep CreateType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateType x -> CreateType
$cfrom :: forall x. CreateType -> Rep CreateType x
Prelude.Generic)

-- |
-- Create a value of 'CreateType' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'apiId', 'createType_apiId' - The API ID.
--
-- 'definition', 'createType_definition' - The type definition, in GraphQL Schema Definition Language (SDL) format.
--
-- For more information, see the
-- <http://graphql.org/learn/schema/ GraphQL SDL documentation>.
--
-- 'format', 'createType_format' - The type format: SDL or JSON.
newCreateType ::
  -- | 'apiId'
  Prelude.Text ->
  -- | 'definition'
  Prelude.Text ->
  -- | 'format'
  TypeDefinitionFormat ->
  CreateType
newCreateType :: Text -> Text -> TypeDefinitionFormat -> CreateType
newCreateType Text
pApiId_ Text
pDefinition_ TypeDefinitionFormat
pFormat_ =
  CreateType' :: Text -> Text -> TypeDefinitionFormat -> CreateType
CreateType'
    { $sel:apiId:CreateType' :: Text
apiId = Text
pApiId_,
      $sel:definition:CreateType' :: Text
definition = Text
pDefinition_,
      $sel:format:CreateType' :: TypeDefinitionFormat
format = TypeDefinitionFormat
pFormat_
    }

-- | The API ID.
createType_apiId :: Lens.Lens' CreateType Prelude.Text
createType_apiId :: (Text -> f Text) -> CreateType -> f CreateType
createType_apiId = (CreateType -> Text)
-> (CreateType -> Text -> CreateType)
-> Lens CreateType CreateType Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateType' {Text
apiId :: Text
$sel:apiId:CreateType' :: CreateType -> Text
apiId} -> Text
apiId) (\s :: CreateType
s@CreateType' {} Text
a -> CreateType
s {$sel:apiId:CreateType' :: Text
apiId = Text
a} :: CreateType)

-- | The type definition, in GraphQL Schema Definition Language (SDL) format.
--
-- For more information, see the
-- <http://graphql.org/learn/schema/ GraphQL SDL documentation>.
createType_definition :: Lens.Lens' CreateType Prelude.Text
createType_definition :: (Text -> f Text) -> CreateType -> f CreateType
createType_definition = (CreateType -> Text)
-> (CreateType -> Text -> CreateType)
-> Lens CreateType CreateType Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateType' {Text
definition :: Text
$sel:definition:CreateType' :: CreateType -> Text
definition} -> Text
definition) (\s :: CreateType
s@CreateType' {} Text
a -> CreateType
s {$sel:definition:CreateType' :: Text
definition = Text
a} :: CreateType)

-- | The type format: SDL or JSON.
createType_format :: Lens.Lens' CreateType TypeDefinitionFormat
createType_format :: (TypeDefinitionFormat -> f TypeDefinitionFormat)
-> CreateType -> f CreateType
createType_format = (CreateType -> TypeDefinitionFormat)
-> (CreateType -> TypeDefinitionFormat -> CreateType)
-> Lens
     CreateType CreateType TypeDefinitionFormat TypeDefinitionFormat
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateType' {TypeDefinitionFormat
format :: TypeDefinitionFormat
$sel:format:CreateType' :: CreateType -> TypeDefinitionFormat
format} -> TypeDefinitionFormat
format) (\s :: CreateType
s@CreateType' {} TypeDefinitionFormat
a -> CreateType
s {$sel:format:CreateType' :: TypeDefinitionFormat
format = TypeDefinitionFormat
a} :: CreateType)

instance Core.AWSRequest CreateType where
  type AWSResponse CreateType = CreateTypeResponse
  request :: CreateType -> Request CreateType
request = Service -> CreateType -> Request CreateType
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateType
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateType)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateType))
-> Logger
-> Service
-> Proxy CreateType
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateType)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Type -> Int -> CreateTypeResponse
CreateTypeResponse'
            (Maybe Type -> Int -> CreateTypeResponse)
-> Either String (Maybe Type)
-> Either String (Int -> CreateTypeResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Type)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"type")
            Either String (Int -> CreateTypeResponse)
-> Either String Int -> Either String CreateTypeResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateType

instance Prelude.NFData CreateType

instance Core.ToHeaders CreateType where
  toHeaders :: CreateType -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateType -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateType where
  toJSON :: CreateType -> Value
toJSON CreateType' {Text
TypeDefinitionFormat
format :: TypeDefinitionFormat
definition :: Text
apiId :: Text
$sel:format:CreateType' :: CreateType -> TypeDefinitionFormat
$sel:definition:CreateType' :: CreateType -> Text
$sel:apiId:CreateType' :: CreateType -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"definition" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
definition),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"format" Text -> TypeDefinitionFormat -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TypeDefinitionFormat
format)
          ]
      )

instance Core.ToPath CreateType where
  toPath :: CreateType -> ByteString
toPath CreateType' {Text
TypeDefinitionFormat
format :: TypeDefinitionFormat
definition :: Text
apiId :: Text
$sel:format:CreateType' :: CreateType -> TypeDefinitionFormat
$sel:definition:CreateType' :: CreateType -> Text
$sel:apiId:CreateType' :: CreateType -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/apis/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
apiId, ByteString
"/types"]

instance Core.ToQuery CreateType where
  toQuery :: CreateType -> QueryString
toQuery = QueryString -> CreateType -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateTypeResponse' smart constructor.
data CreateTypeResponse = CreateTypeResponse'
  { -- | The @Type@ object.
    CreateTypeResponse -> Maybe Type
type' :: Prelude.Maybe Type,
    -- | The response's http status code.
    CreateTypeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateTypeResponse -> CreateTypeResponse -> Bool
(CreateTypeResponse -> CreateTypeResponse -> Bool)
-> (CreateTypeResponse -> CreateTypeResponse -> Bool)
-> Eq CreateTypeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateTypeResponse -> CreateTypeResponse -> Bool
$c/= :: CreateTypeResponse -> CreateTypeResponse -> Bool
== :: CreateTypeResponse -> CreateTypeResponse -> Bool
$c== :: CreateTypeResponse -> CreateTypeResponse -> Bool
Prelude.Eq, ReadPrec [CreateTypeResponse]
ReadPrec CreateTypeResponse
Int -> ReadS CreateTypeResponse
ReadS [CreateTypeResponse]
(Int -> ReadS CreateTypeResponse)
-> ReadS [CreateTypeResponse]
-> ReadPrec CreateTypeResponse
-> ReadPrec [CreateTypeResponse]
-> Read CreateTypeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateTypeResponse]
$creadListPrec :: ReadPrec [CreateTypeResponse]
readPrec :: ReadPrec CreateTypeResponse
$creadPrec :: ReadPrec CreateTypeResponse
readList :: ReadS [CreateTypeResponse]
$creadList :: ReadS [CreateTypeResponse]
readsPrec :: Int -> ReadS CreateTypeResponse
$creadsPrec :: Int -> ReadS CreateTypeResponse
Prelude.Read, Int -> CreateTypeResponse -> ShowS
[CreateTypeResponse] -> ShowS
CreateTypeResponse -> String
(Int -> CreateTypeResponse -> ShowS)
-> (CreateTypeResponse -> String)
-> ([CreateTypeResponse] -> ShowS)
-> Show CreateTypeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateTypeResponse] -> ShowS
$cshowList :: [CreateTypeResponse] -> ShowS
show :: CreateTypeResponse -> String
$cshow :: CreateTypeResponse -> String
showsPrec :: Int -> CreateTypeResponse -> ShowS
$cshowsPrec :: Int -> CreateTypeResponse -> ShowS
Prelude.Show, (forall x. CreateTypeResponse -> Rep CreateTypeResponse x)
-> (forall x. Rep CreateTypeResponse x -> CreateTypeResponse)
-> Generic CreateTypeResponse
forall x. Rep CreateTypeResponse x -> CreateTypeResponse
forall x. CreateTypeResponse -> Rep CreateTypeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateTypeResponse x -> CreateTypeResponse
$cfrom :: forall x. CreateTypeResponse -> Rep CreateTypeResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateTypeResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'type'', 'createTypeResponse_type' - The @Type@ object.
--
-- 'httpStatus', 'createTypeResponse_httpStatus' - The response's http status code.
newCreateTypeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateTypeResponse
newCreateTypeResponse :: Int -> CreateTypeResponse
newCreateTypeResponse Int
pHttpStatus_ =
  CreateTypeResponse' :: Maybe Type -> Int -> CreateTypeResponse
CreateTypeResponse'
    { $sel:type':CreateTypeResponse' :: Maybe Type
type' = Maybe Type
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateTypeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @Type@ object.
createTypeResponse_type :: Lens.Lens' CreateTypeResponse (Prelude.Maybe Type)
createTypeResponse_type :: (Maybe Type -> f (Maybe Type))
-> CreateTypeResponse -> f CreateTypeResponse
createTypeResponse_type = (CreateTypeResponse -> Maybe Type)
-> (CreateTypeResponse -> Maybe Type -> CreateTypeResponse)
-> Lens
     CreateTypeResponse CreateTypeResponse (Maybe Type) (Maybe Type)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTypeResponse' {Maybe Type
type' :: Maybe Type
$sel:type':CreateTypeResponse' :: CreateTypeResponse -> Maybe Type
type'} -> Maybe Type
type') (\s :: CreateTypeResponse
s@CreateTypeResponse' {} Maybe Type
a -> CreateTypeResponse
s {$sel:type':CreateTypeResponse' :: Maybe Type
type' = Maybe Type
a} :: CreateTypeResponse)

-- | The response's http status code.
createTypeResponse_httpStatus :: Lens.Lens' CreateTypeResponse Prelude.Int
createTypeResponse_httpStatus :: (Int -> f Int) -> CreateTypeResponse -> f CreateTypeResponse
createTypeResponse_httpStatus = (CreateTypeResponse -> Int)
-> (CreateTypeResponse -> Int -> CreateTypeResponse)
-> Lens CreateTypeResponse CreateTypeResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateTypeResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateTypeResponse' :: CreateTypeResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateTypeResponse
s@CreateTypeResponse' {} Int
a -> CreateTypeResponse
s {$sel:httpStatus:CreateTypeResponse' :: Int
httpStatus = Int
a} :: CreateTypeResponse)

instance Prelude.NFData CreateTypeResponse