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

    -- * Request Lenses
    getType_apiId,
    getType_typeName,
    getType_format,

    -- * Destructuring the Response
    GetTypeResponse (..),
    newGetTypeResponse,

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

-- |
-- Create a value of 'GetType' 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', 'getType_apiId' - The API ID.
--
-- 'typeName', 'getType_typeName' - The type name.
--
-- 'format', 'getType_format' - The type format: SDL or JSON.
newGetType ::
  -- | 'apiId'
  Prelude.Text ->
  -- | 'typeName'
  Prelude.Text ->
  -- | 'format'
  TypeDefinitionFormat ->
  GetType
newGetType :: Text -> Text -> TypeDefinitionFormat -> GetType
newGetType Text
pApiId_ Text
pTypeName_ TypeDefinitionFormat
pFormat_ =
  GetType' :: Text -> Text -> TypeDefinitionFormat -> GetType
GetType'
    { $sel:apiId:GetType' :: Text
apiId = Text
pApiId_,
      $sel:typeName:GetType' :: Text
typeName = Text
pTypeName_,
      $sel:format:GetType' :: TypeDefinitionFormat
format = TypeDefinitionFormat
pFormat_
    }

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

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

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

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

instance Prelude.NFData GetType

instance Core.ToHeaders GetType where
  toHeaders :: GetType -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetType -> 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.ToPath GetType where
  toPath :: GetType -> ByteString
toPath GetType' {Text
TypeDefinitionFormat
format :: TypeDefinitionFormat
typeName :: Text
apiId :: Text
$sel:format:GetType' :: GetType -> TypeDefinitionFormat
$sel:typeName:GetType' :: GetType -> Text
$sel:apiId:GetType' :: GetType -> 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 GetType where
  toQuery :: GetType -> QueryString
toQuery GetType' {Text
TypeDefinitionFormat
format :: TypeDefinitionFormat
typeName :: Text
apiId :: Text
$sel:format:GetType' :: GetType -> TypeDefinitionFormat
$sel:typeName:GetType' :: GetType -> Text
$sel:apiId:GetType' :: GetType -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"format" ByteString -> TypeDefinitionFormat -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: TypeDefinitionFormat
format]

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

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

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

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

instance Prelude.NFData GetTypeResponse