{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.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:/ 'newGetSchemaAsJson' smart constructor.
data GetSchemaAsJson = GetSchemaAsJson'
  { -- | The ARN of the schema to retrieve.
    GetSchemaAsJson -> Text
schemaArn :: Prelude.Text
  }
  deriving (GetSchemaAsJson -> GetSchemaAsJson -> Bool
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]
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
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. 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' {$sel:schemaArn:GetSchemaAsJson' :: Text
schemaArn = Text
pSchemaArn_}

-- | The ARN of the schema to retrieve.
getSchemaAsJson_schemaArn :: Lens.Lens' GetSchemaAsJson Prelude.Text
getSchemaAsJson_schemaArn :: Lens' GetSchemaAsJson Text
getSchemaAsJson_schemaArn = 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 :: (Service -> Service) -> GetSchemaAsJson -> Request GetSchemaAsJson
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 GetSchemaAsJson
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetSchemaAsJson)))
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 Text -> Maybe Text -> Int -> GetSchemaAsJsonResponse
GetSchemaAsJsonResponse'
            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
"Document")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Name")
            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 GetSchemaAsJson where
  hashWithSalt :: Int -> GetSchemaAsJson -> Int
hashWithSalt Int
_salt GetSchemaAsJson' {Text
schemaArn :: Text
$sel:schemaArn:GetSchemaAsJson' :: GetSchemaAsJson -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
schemaArn

instance Prelude.NFData GetSchemaAsJson where
  rnf :: GetSchemaAsJson -> ()
rnf GetSchemaAsJson' {Text
schemaArn :: Text
$sel:schemaArn:GetSchemaAsJson' :: GetSchemaAsJson -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
schemaArn

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

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

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

instance Data.ToQuery GetSchemaAsJson where
  toQuery :: GetSchemaAsJson -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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. 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'
    { $sel:document:GetSchemaAsJsonResponse' :: Maybe Text
document =
        forall a. Maybe a
Prelude.Nothing,
      $sel:name:GetSchemaAsJsonResponse' :: Maybe Text
name = 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 :: Lens' GetSchemaAsJsonResponse (Maybe Text)
getSchemaAsJsonResponse_document = 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 :: Lens' GetSchemaAsJsonResponse (Maybe Text)
getSchemaAsJsonResponse_name = 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 :: Lens' GetSchemaAsJsonResponse Int
getSchemaAsJsonResponse_httpStatus = 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 where
  rnf :: GetSchemaAsJsonResponse -> ()
rnf GetSchemaAsJsonResponse' {Int
Maybe Text
httpStatus :: Int
name :: Maybe Text
document :: Maybe Text
$sel:httpStatus:GetSchemaAsJsonResponse' :: GetSchemaAsJsonResponse -> Int
$sel:name:GetSchemaAsJsonResponse' :: GetSchemaAsJsonResponse -> Maybe Text
$sel:document:GetSchemaAsJsonResponse' :: GetSchemaAsJsonResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
document
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus