{-# 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.CloudDirectory.GetSchemaAsJson
-- 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 JSON representation of the schema. See
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_jsonformat.html#schemas_json JSON Schema Format>
-- for more information.
module Amazonka.CloudDirectory.GetSchemaAsJson
  ( -- * Creating a Request
    GetSchemaAsJson (..),
    newGetSchemaAsJson,

    -- * Request Lenses
    getSchemaAsJson_schemaArn,

    -- * Destructuring the Response
    GetSchemaAsJsonResponse (..),
    newGetSchemaAsJsonResponse,

    -- * Response Lenses
    getSchemaAsJsonResponse_document,
    getSchemaAsJsonResponse_name,
    getSchemaAsJsonResponse_httpStatus,
  )
where

import Amazonka.CloudDirectory.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:/ 'newGetSchemaAsJson' smart constructor.
data GetSchemaAsJson = GetSchemaAsJson'
  { -- | The ARN of the schema to retrieve.
    GetSchemaAsJson -> Text
schemaArn :: Prelude.Text
  }
  deriving (GetSchemaAsJson -> GetSchemaAsJson -> Bool
(GetSchemaAsJson -> GetSchemaAsJson -> Bool)
-> (GetSchemaAsJson -> GetSchemaAsJson -> Bool)
-> Eq GetSchemaAsJson
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetSchemaAsJson -> GetSchemaAsJson -> Bool
$c/= :: GetSchemaAsJson -> GetSchemaAsJson -> Bool
== :: GetSchemaAsJson -> GetSchemaAsJson -> Bool
$c== :: GetSchemaAsJson -> GetSchemaAsJson -> Bool
Prelude.Eq, ReadPrec [GetSchemaAsJson]
ReadPrec GetSchemaAsJson
Int -> ReadS GetSchemaAsJson
ReadS [GetSchemaAsJson]
(Int -> ReadS GetSchemaAsJson)
-> ReadS [GetSchemaAsJson]
-> ReadPrec GetSchemaAsJson
-> ReadPrec [GetSchemaAsJson]
-> Read GetSchemaAsJson
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetSchemaAsJson]
$creadListPrec :: ReadPrec [GetSchemaAsJson]
readPrec :: ReadPrec GetSchemaAsJson
$creadPrec :: ReadPrec GetSchemaAsJson
readList :: ReadS [GetSchemaAsJson]
$creadList :: ReadS [GetSchemaAsJson]
readsPrec :: Int -> ReadS GetSchemaAsJson
$creadsPrec :: Int -> ReadS GetSchemaAsJson
Prelude.Read, Int -> GetSchemaAsJson -> ShowS
[GetSchemaAsJson] -> ShowS
GetSchemaAsJson -> String
(Int -> GetSchemaAsJson -> ShowS)
-> (GetSchemaAsJson -> String)
-> ([GetSchemaAsJson] -> ShowS)
-> Show GetSchemaAsJson
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetSchemaAsJson] -> ShowS
$cshowList :: [GetSchemaAsJson] -> ShowS
show :: GetSchemaAsJson -> String
$cshow :: GetSchemaAsJson -> String
showsPrec :: Int -> GetSchemaAsJson -> ShowS
$cshowsPrec :: Int -> GetSchemaAsJson -> ShowS
Prelude.Show, (forall x. GetSchemaAsJson -> Rep GetSchemaAsJson x)
-> (forall x. Rep GetSchemaAsJson x -> GetSchemaAsJson)
-> Generic GetSchemaAsJson
forall x. Rep GetSchemaAsJson x -> GetSchemaAsJson
forall x. GetSchemaAsJson -> Rep GetSchemaAsJson x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetSchemaAsJson x -> GetSchemaAsJson
$cfrom :: forall x. GetSchemaAsJson -> Rep GetSchemaAsJson x
Prelude.Generic)

-- |
-- Create a value of 'GetSchemaAsJson' 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:
--
-- 'schemaArn', 'getSchemaAsJson_schemaArn' - The ARN of the schema to retrieve.
newGetSchemaAsJson ::
  -- | 'schemaArn'
  Prelude.Text ->
  GetSchemaAsJson
newGetSchemaAsJson :: Text -> GetSchemaAsJson
newGetSchemaAsJson Text
pSchemaArn_ =
  GetSchemaAsJson' :: Text -> GetSchemaAsJson
GetSchemaAsJson' {$sel:schemaArn:GetSchemaAsJson' :: Text
schemaArn = Text
pSchemaArn_}

-- | The ARN of the schema to retrieve.
getSchemaAsJson_schemaArn :: Lens.Lens' GetSchemaAsJson Prelude.Text
getSchemaAsJson_schemaArn :: (Text -> f Text) -> GetSchemaAsJson -> f GetSchemaAsJson
getSchemaAsJson_schemaArn = (GetSchemaAsJson -> Text)
-> (GetSchemaAsJson -> Text -> GetSchemaAsJson)
-> Lens GetSchemaAsJson GetSchemaAsJson Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSchemaAsJson' {Text
schemaArn :: Text
$sel:schemaArn:GetSchemaAsJson' :: GetSchemaAsJson -> Text
schemaArn} -> Text
schemaArn) (\s :: GetSchemaAsJson
s@GetSchemaAsJson' {} Text
a -> GetSchemaAsJson
s {$sel:schemaArn:GetSchemaAsJson' :: Text
schemaArn = Text
a} :: GetSchemaAsJson)

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

instance Prelude.NFData GetSchemaAsJson

instance Core.ToHeaders GetSchemaAsJson where
  toHeaders :: GetSchemaAsJson -> ResponseHeaders
toHeaders GetSchemaAsJson' {Text
schemaArn :: Text
$sel:schemaArn:GetSchemaAsJson' :: GetSchemaAsJson -> Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-data-partition" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
schemaArn]

instance Core.ToJSON GetSchemaAsJson where
  toJSON :: GetSchemaAsJson -> Value
toJSON = Value -> GetSchemaAsJson -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath GetSchemaAsJson where
  toPath :: GetSchemaAsJson -> ByteString
toPath =
    ByteString -> GetSchemaAsJson -> ByteString
forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/schema/json"

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

-- | /See:/ 'newGetSchemaAsJsonResponse' smart constructor.
data GetSchemaAsJsonResponse = GetSchemaAsJsonResponse'
  { -- | The JSON representation of the schema document.
    GetSchemaAsJsonResponse -> Maybe Text
document :: Prelude.Maybe Prelude.Text,
    -- | The name of the retrieved schema.
    GetSchemaAsJsonResponse -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetSchemaAsJsonResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetSchemaAsJsonResponse -> GetSchemaAsJsonResponse -> Bool
(GetSchemaAsJsonResponse -> GetSchemaAsJsonResponse -> Bool)
-> (GetSchemaAsJsonResponse -> GetSchemaAsJsonResponse -> Bool)
-> Eq GetSchemaAsJsonResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetSchemaAsJsonResponse -> GetSchemaAsJsonResponse -> Bool
$c/= :: GetSchemaAsJsonResponse -> GetSchemaAsJsonResponse -> Bool
== :: GetSchemaAsJsonResponse -> GetSchemaAsJsonResponse -> Bool
$c== :: GetSchemaAsJsonResponse -> GetSchemaAsJsonResponse -> Bool
Prelude.Eq, ReadPrec [GetSchemaAsJsonResponse]
ReadPrec GetSchemaAsJsonResponse
Int -> ReadS GetSchemaAsJsonResponse
ReadS [GetSchemaAsJsonResponse]
(Int -> ReadS GetSchemaAsJsonResponse)
-> ReadS [GetSchemaAsJsonResponse]
-> ReadPrec GetSchemaAsJsonResponse
-> ReadPrec [GetSchemaAsJsonResponse]
-> Read GetSchemaAsJsonResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetSchemaAsJsonResponse]
$creadListPrec :: ReadPrec [GetSchemaAsJsonResponse]
readPrec :: ReadPrec GetSchemaAsJsonResponse
$creadPrec :: ReadPrec GetSchemaAsJsonResponse
readList :: ReadS [GetSchemaAsJsonResponse]
$creadList :: ReadS [GetSchemaAsJsonResponse]
readsPrec :: Int -> ReadS GetSchemaAsJsonResponse
$creadsPrec :: Int -> ReadS GetSchemaAsJsonResponse
Prelude.Read, Int -> GetSchemaAsJsonResponse -> ShowS
[GetSchemaAsJsonResponse] -> ShowS
GetSchemaAsJsonResponse -> String
(Int -> GetSchemaAsJsonResponse -> ShowS)
-> (GetSchemaAsJsonResponse -> String)
-> ([GetSchemaAsJsonResponse] -> ShowS)
-> Show GetSchemaAsJsonResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetSchemaAsJsonResponse] -> ShowS
$cshowList :: [GetSchemaAsJsonResponse] -> ShowS
show :: GetSchemaAsJsonResponse -> String
$cshow :: GetSchemaAsJsonResponse -> String
showsPrec :: Int -> GetSchemaAsJsonResponse -> ShowS
$cshowsPrec :: Int -> GetSchemaAsJsonResponse -> ShowS
Prelude.Show, (forall x.
 GetSchemaAsJsonResponse -> Rep GetSchemaAsJsonResponse x)
-> (forall x.
    Rep GetSchemaAsJsonResponse x -> GetSchemaAsJsonResponse)
-> Generic GetSchemaAsJsonResponse
forall x. Rep GetSchemaAsJsonResponse x -> GetSchemaAsJsonResponse
forall x. GetSchemaAsJsonResponse -> Rep GetSchemaAsJsonResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetSchemaAsJsonResponse x -> GetSchemaAsJsonResponse
$cfrom :: forall x. GetSchemaAsJsonResponse -> Rep GetSchemaAsJsonResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetSchemaAsJsonResponse' 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:
--
-- 'document', 'getSchemaAsJsonResponse_document' - The JSON representation of the schema document.
--
-- 'name', 'getSchemaAsJsonResponse_name' - The name of the retrieved schema.
--
-- 'httpStatus', 'getSchemaAsJsonResponse_httpStatus' - The response's http status code.
newGetSchemaAsJsonResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetSchemaAsJsonResponse
newGetSchemaAsJsonResponse :: Int -> GetSchemaAsJsonResponse
newGetSchemaAsJsonResponse Int
pHttpStatus_ =
  GetSchemaAsJsonResponse' :: Maybe Text -> Maybe Text -> Int -> GetSchemaAsJsonResponse
GetSchemaAsJsonResponse'
    { $sel:document:GetSchemaAsJsonResponse' :: Maybe Text
document =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:GetSchemaAsJsonResponse' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetSchemaAsJsonResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The JSON representation of the schema document.
getSchemaAsJsonResponse_document :: Lens.Lens' GetSchemaAsJsonResponse (Prelude.Maybe Prelude.Text)
getSchemaAsJsonResponse_document :: (Maybe Text -> f (Maybe Text))
-> GetSchemaAsJsonResponse -> f GetSchemaAsJsonResponse
getSchemaAsJsonResponse_document = (GetSchemaAsJsonResponse -> Maybe Text)
-> (GetSchemaAsJsonResponse
    -> Maybe Text -> GetSchemaAsJsonResponse)
-> Lens
     GetSchemaAsJsonResponse
     GetSchemaAsJsonResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSchemaAsJsonResponse' {Maybe Text
document :: Maybe Text
$sel:document:GetSchemaAsJsonResponse' :: GetSchemaAsJsonResponse -> Maybe Text
document} -> Maybe Text
document) (\s :: GetSchemaAsJsonResponse
s@GetSchemaAsJsonResponse' {} Maybe Text
a -> GetSchemaAsJsonResponse
s {$sel:document:GetSchemaAsJsonResponse' :: Maybe Text
document = Maybe Text
a} :: GetSchemaAsJsonResponse)

-- | The name of the retrieved schema.
getSchemaAsJsonResponse_name :: Lens.Lens' GetSchemaAsJsonResponse (Prelude.Maybe Prelude.Text)
getSchemaAsJsonResponse_name :: (Maybe Text -> f (Maybe Text))
-> GetSchemaAsJsonResponse -> f GetSchemaAsJsonResponse
getSchemaAsJsonResponse_name = (GetSchemaAsJsonResponse -> Maybe Text)
-> (GetSchemaAsJsonResponse
    -> Maybe Text -> GetSchemaAsJsonResponse)
-> Lens
     GetSchemaAsJsonResponse
     GetSchemaAsJsonResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetSchemaAsJsonResponse' {Maybe Text
name :: Maybe Text
$sel:name:GetSchemaAsJsonResponse' :: GetSchemaAsJsonResponse -> Maybe Text
name} -> Maybe Text
name) (\s :: GetSchemaAsJsonResponse
s@GetSchemaAsJsonResponse' {} Maybe Text
a -> GetSchemaAsJsonResponse
s {$sel:name:GetSchemaAsJsonResponse' :: Maybe Text
name = Maybe Text
a} :: GetSchemaAsJsonResponse)

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

instance Prelude.NFData GetSchemaAsJsonResponse