{-# 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.StartSchemaCreation
-- 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)
--
-- Adds a new schema to your GraphQL API.
--
-- This operation is asynchronous. Use to determine when it has completed.
module Amazonka.AppSync.StartSchemaCreation
  ( -- * Creating a Request
    StartSchemaCreation (..),
    newStartSchemaCreation,

    -- * Request Lenses
    startSchemaCreation_apiId,
    startSchemaCreation_definition,

    -- * Destructuring the Response
    StartSchemaCreationResponse (..),
    newStartSchemaCreationResponse,

    -- * Response Lenses
    startSchemaCreationResponse_status,
    startSchemaCreationResponse_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:/ 'newStartSchemaCreation' smart constructor.
data StartSchemaCreation = StartSchemaCreation'
  { -- | The API ID.
    StartSchemaCreation -> Text
apiId :: Prelude.Text,
    -- | The schema definition, in GraphQL schema language format.
    StartSchemaCreation -> Base64
definition :: Core.Base64
  }
  deriving (StartSchemaCreation -> StartSchemaCreation -> Bool
(StartSchemaCreation -> StartSchemaCreation -> Bool)
-> (StartSchemaCreation -> StartSchemaCreation -> Bool)
-> Eq StartSchemaCreation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartSchemaCreation -> StartSchemaCreation -> Bool
$c/= :: StartSchemaCreation -> StartSchemaCreation -> Bool
== :: StartSchemaCreation -> StartSchemaCreation -> Bool
$c== :: StartSchemaCreation -> StartSchemaCreation -> Bool
Prelude.Eq, ReadPrec [StartSchemaCreation]
ReadPrec StartSchemaCreation
Int -> ReadS StartSchemaCreation
ReadS [StartSchemaCreation]
(Int -> ReadS StartSchemaCreation)
-> ReadS [StartSchemaCreation]
-> ReadPrec StartSchemaCreation
-> ReadPrec [StartSchemaCreation]
-> Read StartSchemaCreation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartSchemaCreation]
$creadListPrec :: ReadPrec [StartSchemaCreation]
readPrec :: ReadPrec StartSchemaCreation
$creadPrec :: ReadPrec StartSchemaCreation
readList :: ReadS [StartSchemaCreation]
$creadList :: ReadS [StartSchemaCreation]
readsPrec :: Int -> ReadS StartSchemaCreation
$creadsPrec :: Int -> ReadS StartSchemaCreation
Prelude.Read, Int -> StartSchemaCreation -> ShowS
[StartSchemaCreation] -> ShowS
StartSchemaCreation -> String
(Int -> StartSchemaCreation -> ShowS)
-> (StartSchemaCreation -> String)
-> ([StartSchemaCreation] -> ShowS)
-> Show StartSchemaCreation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartSchemaCreation] -> ShowS
$cshowList :: [StartSchemaCreation] -> ShowS
show :: StartSchemaCreation -> String
$cshow :: StartSchemaCreation -> String
showsPrec :: Int -> StartSchemaCreation -> ShowS
$cshowsPrec :: Int -> StartSchemaCreation -> ShowS
Prelude.Show, (forall x. StartSchemaCreation -> Rep StartSchemaCreation x)
-> (forall x. Rep StartSchemaCreation x -> StartSchemaCreation)
-> Generic StartSchemaCreation
forall x. Rep StartSchemaCreation x -> StartSchemaCreation
forall x. StartSchemaCreation -> Rep StartSchemaCreation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartSchemaCreation x -> StartSchemaCreation
$cfrom :: forall x. StartSchemaCreation -> Rep StartSchemaCreation x
Prelude.Generic)

-- |
-- Create a value of 'StartSchemaCreation' 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', 'startSchemaCreation_apiId' - The API ID.
--
-- 'definition', 'startSchemaCreation_definition' - The schema definition, in GraphQL schema language format.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
newStartSchemaCreation ::
  -- | 'apiId'
  Prelude.Text ->
  -- | 'definition'
  Prelude.ByteString ->
  StartSchemaCreation
newStartSchemaCreation :: Text -> ByteString -> StartSchemaCreation
newStartSchemaCreation Text
pApiId_ ByteString
pDefinition_ =
  StartSchemaCreation' :: Text -> Base64 -> StartSchemaCreation
StartSchemaCreation'
    { $sel:apiId:StartSchemaCreation' :: Text
apiId = Text
pApiId_,
      $sel:definition:StartSchemaCreation' :: Base64
definition = Tagged ByteString (Identity ByteString)
-> Tagged Base64 (Identity Base64)
Iso' Base64 ByteString
Core._Base64 (Tagged ByteString (Identity ByteString)
 -> Tagged Base64 (Identity Base64))
-> ByteString -> Base64
forall t b. AReview t b -> b -> t
Lens.# ByteString
pDefinition_
    }

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

-- | The schema definition, in GraphQL schema language format.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
startSchemaCreation_definition :: Lens.Lens' StartSchemaCreation Prelude.ByteString
startSchemaCreation_definition :: (ByteString -> f ByteString)
-> StartSchemaCreation -> f StartSchemaCreation
startSchemaCreation_definition = (StartSchemaCreation -> Base64)
-> (StartSchemaCreation -> Base64 -> StartSchemaCreation)
-> Lens StartSchemaCreation StartSchemaCreation Base64 Base64
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartSchemaCreation' {Base64
definition :: Base64
$sel:definition:StartSchemaCreation' :: StartSchemaCreation -> Base64
definition} -> Base64
definition) (\s :: StartSchemaCreation
s@StartSchemaCreation' {} Base64
a -> StartSchemaCreation
s {$sel:definition:StartSchemaCreation' :: Base64
definition = Base64
a} :: StartSchemaCreation) ((Base64 -> f Base64)
 -> StartSchemaCreation -> f StartSchemaCreation)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> StartSchemaCreation
-> f StartSchemaCreation
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

instance Core.AWSRequest StartSchemaCreation where
  type
    AWSResponse StartSchemaCreation =
      StartSchemaCreationResponse
  request :: StartSchemaCreation -> Request StartSchemaCreation
request = Service -> StartSchemaCreation -> Request StartSchemaCreation
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartSchemaCreation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartSchemaCreation)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartSchemaCreation))
-> Logger
-> Service
-> Proxy StartSchemaCreation
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartSchemaCreation)))
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 SchemaStatus -> Int -> StartSchemaCreationResponse
StartSchemaCreationResponse'
            (Maybe SchemaStatus -> Int -> StartSchemaCreationResponse)
-> Either String (Maybe SchemaStatus)
-> Either String (Int -> StartSchemaCreationResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe SchemaStatus)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"status")
            Either String (Int -> StartSchemaCreationResponse)
-> Either String Int -> Either String StartSchemaCreationResponse
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 StartSchemaCreation

instance Prelude.NFData StartSchemaCreation

instance Core.ToHeaders StartSchemaCreation where
  toHeaders :: StartSchemaCreation -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartSchemaCreation -> 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 StartSchemaCreation where
  toJSON :: StartSchemaCreation -> Value
toJSON StartSchemaCreation' {Text
Base64
definition :: Base64
apiId :: Text
$sel:definition:StartSchemaCreation' :: StartSchemaCreation -> Base64
$sel:apiId:StartSchemaCreation' :: StartSchemaCreation -> 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 -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Base64
definition)]
      )

instance Core.ToPath StartSchemaCreation where
  toPath :: StartSchemaCreation -> ByteString
toPath StartSchemaCreation' {Text
Base64
definition :: Base64
apiId :: Text
$sel:definition:StartSchemaCreation' :: StartSchemaCreation -> Base64
$sel:apiId:StartSchemaCreation' :: StartSchemaCreation -> 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
"/schemacreation"]

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

-- | /See:/ 'newStartSchemaCreationResponse' smart constructor.
data StartSchemaCreationResponse = StartSchemaCreationResponse'
  { -- | The current state of the schema (PROCESSING, FAILED, SUCCESS, or
    -- NOT_APPLICABLE). When the schema is in the ACTIVE state, you can add
    -- data.
    StartSchemaCreationResponse -> Maybe SchemaStatus
status :: Prelude.Maybe SchemaStatus,
    -- | The response's http status code.
    StartSchemaCreationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartSchemaCreationResponse -> StartSchemaCreationResponse -> Bool
(StartSchemaCreationResponse
 -> StartSchemaCreationResponse -> Bool)
-> (StartSchemaCreationResponse
    -> StartSchemaCreationResponse -> Bool)
-> Eq StartSchemaCreationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartSchemaCreationResponse -> StartSchemaCreationResponse -> Bool
$c/= :: StartSchemaCreationResponse -> StartSchemaCreationResponse -> Bool
== :: StartSchemaCreationResponse -> StartSchemaCreationResponse -> Bool
$c== :: StartSchemaCreationResponse -> StartSchemaCreationResponse -> Bool
Prelude.Eq, ReadPrec [StartSchemaCreationResponse]
ReadPrec StartSchemaCreationResponse
Int -> ReadS StartSchemaCreationResponse
ReadS [StartSchemaCreationResponse]
(Int -> ReadS StartSchemaCreationResponse)
-> ReadS [StartSchemaCreationResponse]
-> ReadPrec StartSchemaCreationResponse
-> ReadPrec [StartSchemaCreationResponse]
-> Read StartSchemaCreationResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartSchemaCreationResponse]
$creadListPrec :: ReadPrec [StartSchemaCreationResponse]
readPrec :: ReadPrec StartSchemaCreationResponse
$creadPrec :: ReadPrec StartSchemaCreationResponse
readList :: ReadS [StartSchemaCreationResponse]
$creadList :: ReadS [StartSchemaCreationResponse]
readsPrec :: Int -> ReadS StartSchemaCreationResponse
$creadsPrec :: Int -> ReadS StartSchemaCreationResponse
Prelude.Read, Int -> StartSchemaCreationResponse -> ShowS
[StartSchemaCreationResponse] -> ShowS
StartSchemaCreationResponse -> String
(Int -> StartSchemaCreationResponse -> ShowS)
-> (StartSchemaCreationResponse -> String)
-> ([StartSchemaCreationResponse] -> ShowS)
-> Show StartSchemaCreationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartSchemaCreationResponse] -> ShowS
$cshowList :: [StartSchemaCreationResponse] -> ShowS
show :: StartSchemaCreationResponse -> String
$cshow :: StartSchemaCreationResponse -> String
showsPrec :: Int -> StartSchemaCreationResponse -> ShowS
$cshowsPrec :: Int -> StartSchemaCreationResponse -> ShowS
Prelude.Show, (forall x.
 StartSchemaCreationResponse -> Rep StartSchemaCreationResponse x)
-> (forall x.
    Rep StartSchemaCreationResponse x -> StartSchemaCreationResponse)
-> Generic StartSchemaCreationResponse
forall x.
Rep StartSchemaCreationResponse x -> StartSchemaCreationResponse
forall x.
StartSchemaCreationResponse -> Rep StartSchemaCreationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartSchemaCreationResponse x -> StartSchemaCreationResponse
$cfrom :: forall x.
StartSchemaCreationResponse -> Rep StartSchemaCreationResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartSchemaCreationResponse' 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:
--
-- 'status', 'startSchemaCreationResponse_status' - The current state of the schema (PROCESSING, FAILED, SUCCESS, or
-- NOT_APPLICABLE). When the schema is in the ACTIVE state, you can add
-- data.
--
-- 'httpStatus', 'startSchemaCreationResponse_httpStatus' - The response's http status code.
newStartSchemaCreationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartSchemaCreationResponse
newStartSchemaCreationResponse :: Int -> StartSchemaCreationResponse
newStartSchemaCreationResponse Int
pHttpStatus_ =
  StartSchemaCreationResponse' :: Maybe SchemaStatus -> Int -> StartSchemaCreationResponse
StartSchemaCreationResponse'
    { $sel:status:StartSchemaCreationResponse' :: Maybe SchemaStatus
status =
        Maybe SchemaStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartSchemaCreationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The current state of the schema (PROCESSING, FAILED, SUCCESS, or
-- NOT_APPLICABLE). When the schema is in the ACTIVE state, you can add
-- data.
startSchemaCreationResponse_status :: Lens.Lens' StartSchemaCreationResponse (Prelude.Maybe SchemaStatus)
startSchemaCreationResponse_status :: (Maybe SchemaStatus -> f (Maybe SchemaStatus))
-> StartSchemaCreationResponse -> f StartSchemaCreationResponse
startSchemaCreationResponse_status = (StartSchemaCreationResponse -> Maybe SchemaStatus)
-> (StartSchemaCreationResponse
    -> Maybe SchemaStatus -> StartSchemaCreationResponse)
-> Lens
     StartSchemaCreationResponse
     StartSchemaCreationResponse
     (Maybe SchemaStatus)
     (Maybe SchemaStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartSchemaCreationResponse' {Maybe SchemaStatus
status :: Maybe SchemaStatus
$sel:status:StartSchemaCreationResponse' :: StartSchemaCreationResponse -> Maybe SchemaStatus
status} -> Maybe SchemaStatus
status) (\s :: StartSchemaCreationResponse
s@StartSchemaCreationResponse' {} Maybe SchemaStatus
a -> StartSchemaCreationResponse
s {$sel:status:StartSchemaCreationResponse' :: Maybe SchemaStatus
status = Maybe SchemaStatus
a} :: StartSchemaCreationResponse)

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

instance Prelude.NFData StartSchemaCreationResponse