{-# 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.UpdateType
-- 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)
--
-- Updates a @Type@ object.
module Amazonka.AppSync.UpdateType
  ( -- * Creating a Request
    UpdateType (..),
    newUpdateType,

    -- * Request Lenses
    updateType_definition,
    updateType_apiId,
    updateType_typeName,
    updateType_format,

    -- * Destructuring the Response
    UpdateTypeResponse (..),
    newUpdateTypeResponse,

    -- * Response Lenses
    updateTypeResponse_type,
    updateTypeResponse_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:/ 'newUpdateType' smart constructor.
data UpdateType = UpdateType'
  { -- | The new definition.
    UpdateType -> Maybe Text
definition :: Prelude.Maybe Prelude.Text,
    -- | The API ID.
    UpdateType -> Text
apiId :: Prelude.Text,
    -- | The new type name.
    UpdateType -> Text
typeName :: Prelude.Text,
    -- | The new type format: SDL or JSON.
    UpdateType -> TypeDefinitionFormat
format :: TypeDefinitionFormat
  }
  deriving (UpdateType -> UpdateType -> Bool
(UpdateType -> UpdateType -> Bool)
-> (UpdateType -> UpdateType -> Bool) -> Eq UpdateType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateType -> UpdateType -> Bool
$c/= :: UpdateType -> UpdateType -> Bool
== :: UpdateType -> UpdateType -> Bool
$c== :: UpdateType -> UpdateType -> Bool
Prelude.Eq, ReadPrec [UpdateType]
ReadPrec UpdateType
Int -> ReadS UpdateType
ReadS [UpdateType]
(Int -> ReadS UpdateType)
-> ReadS [UpdateType]
-> ReadPrec UpdateType
-> ReadPrec [UpdateType]
-> Read UpdateType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateType]
$creadListPrec :: ReadPrec [UpdateType]
readPrec :: ReadPrec UpdateType
$creadPrec :: ReadPrec UpdateType
readList :: ReadS [UpdateType]
$creadList :: ReadS [UpdateType]
readsPrec :: Int -> ReadS UpdateType
$creadsPrec :: Int -> ReadS UpdateType
Prelude.Read, Int -> UpdateType -> ShowS
[UpdateType] -> ShowS
UpdateType -> String
(Int -> UpdateType -> ShowS)
-> (UpdateType -> String)
-> ([UpdateType] -> ShowS)
-> Show UpdateType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateType] -> ShowS
$cshowList :: [UpdateType] -> ShowS
show :: UpdateType -> String
$cshow :: UpdateType -> String
showsPrec :: Int -> UpdateType -> ShowS
$cshowsPrec :: Int -> UpdateType -> ShowS
Prelude.Show, (forall x. UpdateType -> Rep UpdateType x)
-> (forall x. Rep UpdateType x -> UpdateType) -> Generic UpdateType
forall x. Rep UpdateType x -> UpdateType
forall x. UpdateType -> Rep UpdateType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateType x -> UpdateType
$cfrom :: forall x. UpdateType -> Rep UpdateType x
Prelude.Generic)

-- |
-- Create a value of 'UpdateType' 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:
--
-- 'definition', 'updateType_definition' - The new definition.
--
-- 'apiId', 'updateType_apiId' - The API ID.
--
-- 'typeName', 'updateType_typeName' - The new type name.
--
-- 'format', 'updateType_format' - The new type format: SDL or JSON.
newUpdateType ::
  -- | 'apiId'
  Prelude.Text ->
  -- | 'typeName'
  Prelude.Text ->
  -- | 'format'
  TypeDefinitionFormat ->
  UpdateType
newUpdateType :: Text -> Text -> TypeDefinitionFormat -> UpdateType
newUpdateType Text
pApiId_ Text
pTypeName_ TypeDefinitionFormat
pFormat_ =
  UpdateType' :: Maybe Text -> Text -> Text -> TypeDefinitionFormat -> UpdateType
UpdateType'
    { $sel:definition:UpdateType' :: Maybe Text
definition = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:apiId:UpdateType' :: Text
apiId = Text
pApiId_,
      $sel:typeName:UpdateType' :: Text
typeName = Text
pTypeName_,
      $sel:format:UpdateType' :: TypeDefinitionFormat
format = TypeDefinitionFormat
pFormat_
    }

-- | The new definition.
updateType_definition :: Lens.Lens' UpdateType (Prelude.Maybe Prelude.Text)
updateType_definition :: (Maybe Text -> f (Maybe Text)) -> UpdateType -> f UpdateType
updateType_definition = (UpdateType -> Maybe Text)
-> (UpdateType -> Maybe Text -> UpdateType)
-> Lens UpdateType UpdateType (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateType' {Maybe Text
definition :: Maybe Text
$sel:definition:UpdateType' :: UpdateType -> Maybe Text
definition} -> Maybe Text
definition) (\s :: UpdateType
s@UpdateType' {} Maybe Text
a -> UpdateType
s {$sel:definition:UpdateType' :: Maybe Text
definition = Maybe Text
a} :: UpdateType)

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

-- | The new type name.
updateType_typeName :: Lens.Lens' UpdateType Prelude.Text
updateType_typeName :: (Text -> f Text) -> UpdateType -> f UpdateType
updateType_typeName = (UpdateType -> Text)
-> (UpdateType -> Text -> UpdateType)
-> Lens UpdateType UpdateType Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateType' {Text
typeName :: Text
$sel:typeName:UpdateType' :: UpdateType -> Text
typeName} -> Text
typeName) (\s :: UpdateType
s@UpdateType' {} Text
a -> UpdateType
s {$sel:typeName:UpdateType' :: Text
typeName = Text
a} :: UpdateType)

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

instance Core.AWSRequest UpdateType where
  type AWSResponse UpdateType = UpdateTypeResponse
  request :: UpdateType -> Request UpdateType
request = Service -> UpdateType -> Request UpdateType
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateType
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateType)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateType))
-> Logger
-> Service
-> Proxy UpdateType
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateType)))
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 -> UpdateTypeResponse
UpdateTypeResponse'
            (Maybe Type -> Int -> UpdateTypeResponse)
-> Either String (Maybe Type)
-> Either String (Int -> UpdateTypeResponse)
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 -> UpdateTypeResponse)
-> Either String Int -> Either String UpdateTypeResponse
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 UpdateType

instance Prelude.NFData UpdateType

instance Core.ToHeaders UpdateType where
  toHeaders :: UpdateType -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateType -> 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 UpdateType where
  toJSON :: UpdateType -> Value
toJSON UpdateType' {Maybe Text
Text
TypeDefinitionFormat
format :: TypeDefinitionFormat
typeName :: Text
apiId :: Text
definition :: Maybe Text
$sel:format:UpdateType' :: UpdateType -> TypeDefinitionFormat
$sel:typeName:UpdateType' :: UpdateType -> Text
$sel:apiId:UpdateType' :: UpdateType -> Text
$sel:definition:UpdateType' :: UpdateType -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"definition" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe 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 UpdateType where
  toPath :: UpdateType -> ByteString
toPath UpdateType' {Maybe Text
Text
TypeDefinitionFormat
format :: TypeDefinitionFormat
typeName :: Text
apiId :: Text
definition :: Maybe Text
$sel:format:UpdateType' :: UpdateType -> TypeDefinitionFormat
$sel:typeName:UpdateType' :: UpdateType -> Text
$sel:apiId:UpdateType' :: UpdateType -> Text
$sel:definition:UpdateType' :: UpdateType -> Maybe 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/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
typeName
      ]

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

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

-- |
-- Create a value of 'UpdateTypeResponse' 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'', 'updateTypeResponse_type' - The updated @Type@ object.
--
-- 'httpStatus', 'updateTypeResponse_httpStatus' - The response's http status code.
newUpdateTypeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateTypeResponse
newUpdateTypeResponse :: Int -> UpdateTypeResponse
newUpdateTypeResponse Int
pHttpStatus_ =
  UpdateTypeResponse' :: Maybe Type -> Int -> UpdateTypeResponse
UpdateTypeResponse'
    { $sel:type':UpdateTypeResponse' :: Maybe Type
type' = Maybe Type
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateTypeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

instance Prelude.NFData UpdateTypeResponse