{-# 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.PutSchemaFromJson
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Allows a schema to be updated using JSON upload. Only available for
-- development schemas. See
-- <https://docs.aws.amazon.com/clouddirectory/latest/developerguide/schemas_jsonformat.html#schemas_json JSON Schema Format>
-- for more information.
module Amazonka.CloudDirectory.PutSchemaFromJson
  ( -- * Creating a Request
    PutSchemaFromJson (..),
    newPutSchemaFromJson,

    -- * Request Lenses
    putSchemaFromJson_schemaArn,
    putSchemaFromJson_document,

    -- * Destructuring the Response
    PutSchemaFromJsonResponse (..),
    newPutSchemaFromJsonResponse,

    -- * Response Lenses
    putSchemaFromJsonResponse_arn,
    putSchemaFromJsonResponse_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:/ 'newPutSchemaFromJson' smart constructor.
data PutSchemaFromJson = PutSchemaFromJson'
  { -- | The ARN of the schema to update.
    PutSchemaFromJson -> Text
schemaArn :: Prelude.Text,
    -- | The replacement JSON schema.
    PutSchemaFromJson -> Text
document :: Prelude.Text
  }
  deriving (PutSchemaFromJson -> PutSchemaFromJson -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutSchemaFromJson -> PutSchemaFromJson -> Bool
$c/= :: PutSchemaFromJson -> PutSchemaFromJson -> Bool
== :: PutSchemaFromJson -> PutSchemaFromJson -> Bool
$c== :: PutSchemaFromJson -> PutSchemaFromJson -> Bool
Prelude.Eq, ReadPrec [PutSchemaFromJson]
ReadPrec PutSchemaFromJson
Int -> ReadS PutSchemaFromJson
ReadS [PutSchemaFromJson]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutSchemaFromJson]
$creadListPrec :: ReadPrec [PutSchemaFromJson]
readPrec :: ReadPrec PutSchemaFromJson
$creadPrec :: ReadPrec PutSchemaFromJson
readList :: ReadS [PutSchemaFromJson]
$creadList :: ReadS [PutSchemaFromJson]
readsPrec :: Int -> ReadS PutSchemaFromJson
$creadsPrec :: Int -> ReadS PutSchemaFromJson
Prelude.Read, Int -> PutSchemaFromJson -> ShowS
[PutSchemaFromJson] -> ShowS
PutSchemaFromJson -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutSchemaFromJson] -> ShowS
$cshowList :: [PutSchemaFromJson] -> ShowS
show :: PutSchemaFromJson -> String
$cshow :: PutSchemaFromJson -> String
showsPrec :: Int -> PutSchemaFromJson -> ShowS
$cshowsPrec :: Int -> PutSchemaFromJson -> ShowS
Prelude.Show, forall x. Rep PutSchemaFromJson x -> PutSchemaFromJson
forall x. PutSchemaFromJson -> Rep PutSchemaFromJson x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutSchemaFromJson x -> PutSchemaFromJson
$cfrom :: forall x. PutSchemaFromJson -> Rep PutSchemaFromJson x
Prelude.Generic)

-- |
-- Create a value of 'PutSchemaFromJson' 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', 'putSchemaFromJson_schemaArn' - The ARN of the schema to update.
--
-- 'document', 'putSchemaFromJson_document' - The replacement JSON schema.
newPutSchemaFromJson ::
  -- | 'schemaArn'
  Prelude.Text ->
  -- | 'document'
  Prelude.Text ->
  PutSchemaFromJson
newPutSchemaFromJson :: Text -> Text -> PutSchemaFromJson
newPutSchemaFromJson Text
pSchemaArn_ Text
pDocument_ =
  PutSchemaFromJson'
    { $sel:schemaArn:PutSchemaFromJson' :: Text
schemaArn = Text
pSchemaArn_,
      $sel:document:PutSchemaFromJson' :: Text
document = Text
pDocument_
    }

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

-- | The replacement JSON schema.
putSchemaFromJson_document :: Lens.Lens' PutSchemaFromJson Prelude.Text
putSchemaFromJson_document :: Lens' PutSchemaFromJson Text
putSchemaFromJson_document = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutSchemaFromJson' {Text
document :: Text
$sel:document:PutSchemaFromJson' :: PutSchemaFromJson -> Text
document} -> Text
document) (\s :: PutSchemaFromJson
s@PutSchemaFromJson' {} Text
a -> PutSchemaFromJson
s {$sel:document:PutSchemaFromJson' :: Text
document = Text
a} :: PutSchemaFromJson)

instance Core.AWSRequest PutSchemaFromJson where
  type
    AWSResponse PutSchemaFromJson =
      PutSchemaFromJsonResponse
  request :: (Service -> Service)
-> PutSchemaFromJson -> Request PutSchemaFromJson
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutSchemaFromJson
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutSchemaFromJson)))
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 -> Int -> PutSchemaFromJsonResponse
PutSchemaFromJsonResponse'
            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
"Arn")
            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 PutSchemaFromJson where
  hashWithSalt :: Int -> PutSchemaFromJson -> Int
hashWithSalt Int
_salt PutSchemaFromJson' {Text
document :: Text
schemaArn :: Text
$sel:document:PutSchemaFromJson' :: PutSchemaFromJson -> Text
$sel:schemaArn:PutSchemaFromJson' :: PutSchemaFromJson -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
schemaArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
document

instance Prelude.NFData PutSchemaFromJson where
  rnf :: PutSchemaFromJson -> ()
rnf PutSchemaFromJson' {Text
document :: Text
schemaArn :: Text
$sel:document:PutSchemaFromJson' :: PutSchemaFromJson -> Text
$sel:schemaArn:PutSchemaFromJson' :: PutSchemaFromJson -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
schemaArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
document

instance Data.ToHeaders PutSchemaFromJson where
  toHeaders :: PutSchemaFromJson -> ResponseHeaders
toHeaders PutSchemaFromJson' {Text
document :: Text
schemaArn :: Text
$sel:document:PutSchemaFromJson' :: PutSchemaFromJson -> Text
$sel:schemaArn:PutSchemaFromJson' :: PutSchemaFromJson -> 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 PutSchemaFromJson where
  toJSON :: PutSchemaFromJson -> Value
toJSON PutSchemaFromJson' {Text
document :: Text
schemaArn :: Text
$sel:document:PutSchemaFromJson' :: PutSchemaFromJson -> Text
$sel:schemaArn:PutSchemaFromJson' :: PutSchemaFromJson -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Document" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
document)]
      )

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

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

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

-- |
-- Create a value of 'PutSchemaFromJsonResponse' 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:
--
-- 'arn', 'putSchemaFromJsonResponse_arn' - The ARN of the schema to update.
--
-- 'httpStatus', 'putSchemaFromJsonResponse_httpStatus' - The response's http status code.
newPutSchemaFromJsonResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutSchemaFromJsonResponse
newPutSchemaFromJsonResponse :: Int -> PutSchemaFromJsonResponse
newPutSchemaFromJsonResponse Int
pHttpStatus_ =
  PutSchemaFromJsonResponse'
    { $sel:arn:PutSchemaFromJsonResponse' :: Maybe Text
arn = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutSchemaFromJsonResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the schema to update.
putSchemaFromJsonResponse_arn :: Lens.Lens' PutSchemaFromJsonResponse (Prelude.Maybe Prelude.Text)
putSchemaFromJsonResponse_arn :: Lens' PutSchemaFromJsonResponse (Maybe Text)
putSchemaFromJsonResponse_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutSchemaFromJsonResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:PutSchemaFromJsonResponse' :: PutSchemaFromJsonResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: PutSchemaFromJsonResponse
s@PutSchemaFromJsonResponse' {} Maybe Text
a -> PutSchemaFromJsonResponse
s {$sel:arn:PutSchemaFromJsonResponse' :: Maybe Text
arn = Maybe Text
a} :: PutSchemaFromJsonResponse)

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

instance Prelude.NFData PutSchemaFromJsonResponse where
  rnf :: PutSchemaFromJsonResponse -> ()
rnf PutSchemaFromJsonResponse' {Int
Maybe Text
httpStatus :: Int
arn :: Maybe Text
$sel:httpStatus:PutSchemaFromJsonResponse' :: PutSchemaFromJsonResponse -> Int
$sel:arn:PutSchemaFromJsonResponse' :: PutSchemaFromJsonResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus