{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 :: Data.Base64
  }
  deriving (StartSchemaCreation -> StartSchemaCreation -> Bool
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]
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
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. 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'
    { $sel:apiId:StartSchemaCreation' :: Text
apiId = Text
pApiId_,
      $sel:definition:StartSchemaCreation' :: Base64
definition = Iso' Base64 ByteString
Data._Base64 forall t b. AReview t b -> b -> t
Lens.# ByteString
pDefinition_
    }

-- | The API ID.
startSchemaCreation_apiId :: Lens.Lens' StartSchemaCreation Prelude.Text
startSchemaCreation_apiId :: Lens' StartSchemaCreation Text
startSchemaCreation_apiId = 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 :: Lens' StartSchemaCreation ByteString
startSchemaCreation_definition = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Iso' Base64 ByteString
Data._Base64

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

instance Prelude.Hashable StartSchemaCreation where
  hashWithSalt :: Int -> StartSchemaCreation -> Int
hashWithSalt Int
_salt StartSchemaCreation' {Text
Base64
definition :: Base64
apiId :: Text
$sel:definition:StartSchemaCreation' :: StartSchemaCreation -> Base64
$sel:apiId:StartSchemaCreation' :: StartSchemaCreation -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
apiId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Base64
definition

instance Prelude.NFData StartSchemaCreation where
  rnf :: StartSchemaCreation -> ()
rnf StartSchemaCreation' {Text
Base64
definition :: Base64
apiId :: Text
$sel:definition:StartSchemaCreation' :: StartSchemaCreation -> Base64
$sel:apiId:StartSchemaCreation' :: StartSchemaCreation -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
apiId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Base64
definition

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"definition" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Base64
definition)]
      )

instance Data.ToPath StartSchemaCreation where
  toPath :: StartSchemaCreation -> ByteString
toPath StartSchemaCreation' {Text
Base64
definition :: Base64
apiId :: Text
$sel:definition:StartSchemaCreation' :: StartSchemaCreation -> Base64
$sel:apiId:StartSchemaCreation' :: StartSchemaCreation -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v1/apis/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
apiId, ByteString
"/schemacreation"]

instance Data.ToQuery StartSchemaCreation where
  toQuery :: StartSchemaCreation -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:status:StartSchemaCreationResponse' :: Maybe SchemaStatus
status =
        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 :: Lens' StartSchemaCreationResponse (Maybe SchemaStatus)
startSchemaCreationResponse_status = 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 :: Lens' StartSchemaCreationResponse Int
startSchemaCreationResponse_httpStatus = 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 where
  rnf :: StartSchemaCreationResponse -> ()
rnf StartSchemaCreationResponse' {Int
Maybe SchemaStatus
httpStatus :: Int
status :: Maybe SchemaStatus
$sel:httpStatus:StartSchemaCreationResponse' :: StartSchemaCreationResponse -> Int
$sel:status:StartSchemaCreationResponse' :: StartSchemaCreationResponse -> Maybe SchemaStatus
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe SchemaStatus
status
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus