{-# 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.LexV2Models.CreateResourcePolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a new resource policy with the specified policy statements.
module Amazonka.LexV2Models.CreateResourcePolicy
  ( -- * Creating a Request
    CreateResourcePolicy (..),
    newCreateResourcePolicy,

    -- * Request Lenses
    createResourcePolicy_resourceArn,
    createResourcePolicy_policy,

    -- * Destructuring the Response
    CreateResourcePolicyResponse (..),
    newCreateResourcePolicyResponse,

    -- * Response Lenses
    createResourcePolicyResponse_resourceArn,
    createResourcePolicyResponse_revisionId,
    createResourcePolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LexV2Models.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateResourcePolicy' smart constructor.
data CreateResourcePolicy = CreateResourcePolicy'
  { -- | The Amazon Resource Name (ARN) of the bot or bot alias that the resource
    -- policy is attached to.
    CreateResourcePolicy -> Text
resourceArn :: Prelude.Text,
    -- | A resource policy to add to the resource. The policy is a JSON structure
    -- that contains one or more statements that define the policy. The policy
    -- must follow the IAM syntax. For more information about the contents of a
    -- JSON policy document, see
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html IAM JSON policy reference>
    -- .
    --
    -- If the policy isn\'t valid, Amazon Lex returns a validation exception.
    CreateResourcePolicy -> Text
policy :: Prelude.Text
  }
  deriving (CreateResourcePolicy -> CreateResourcePolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateResourcePolicy -> CreateResourcePolicy -> Bool
$c/= :: CreateResourcePolicy -> CreateResourcePolicy -> Bool
== :: CreateResourcePolicy -> CreateResourcePolicy -> Bool
$c== :: CreateResourcePolicy -> CreateResourcePolicy -> Bool
Prelude.Eq, ReadPrec [CreateResourcePolicy]
ReadPrec CreateResourcePolicy
Int -> ReadS CreateResourcePolicy
ReadS [CreateResourcePolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateResourcePolicy]
$creadListPrec :: ReadPrec [CreateResourcePolicy]
readPrec :: ReadPrec CreateResourcePolicy
$creadPrec :: ReadPrec CreateResourcePolicy
readList :: ReadS [CreateResourcePolicy]
$creadList :: ReadS [CreateResourcePolicy]
readsPrec :: Int -> ReadS CreateResourcePolicy
$creadsPrec :: Int -> ReadS CreateResourcePolicy
Prelude.Read, Int -> CreateResourcePolicy -> ShowS
[CreateResourcePolicy] -> ShowS
CreateResourcePolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateResourcePolicy] -> ShowS
$cshowList :: [CreateResourcePolicy] -> ShowS
show :: CreateResourcePolicy -> String
$cshow :: CreateResourcePolicy -> String
showsPrec :: Int -> CreateResourcePolicy -> ShowS
$cshowsPrec :: Int -> CreateResourcePolicy -> ShowS
Prelude.Show, forall x. Rep CreateResourcePolicy x -> CreateResourcePolicy
forall x. CreateResourcePolicy -> Rep CreateResourcePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateResourcePolicy x -> CreateResourcePolicy
$cfrom :: forall x. CreateResourcePolicy -> Rep CreateResourcePolicy x
Prelude.Generic)

-- |
-- Create a value of 'CreateResourcePolicy' 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:
--
-- 'resourceArn', 'createResourcePolicy_resourceArn' - The Amazon Resource Name (ARN) of the bot or bot alias that the resource
-- policy is attached to.
--
-- 'policy', 'createResourcePolicy_policy' - A resource policy to add to the resource. The policy is a JSON structure
-- that contains one or more statements that define the policy. The policy
-- must follow the IAM syntax. For more information about the contents of a
-- JSON policy document, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html IAM JSON policy reference>
-- .
--
-- If the policy isn\'t valid, Amazon Lex returns a validation exception.
newCreateResourcePolicy ::
  -- | 'resourceArn'
  Prelude.Text ->
  -- | 'policy'
  Prelude.Text ->
  CreateResourcePolicy
newCreateResourcePolicy :: Text -> Text -> CreateResourcePolicy
newCreateResourcePolicy Text
pResourceArn_ Text
pPolicy_ =
  CreateResourcePolicy'
    { $sel:resourceArn:CreateResourcePolicy' :: Text
resourceArn = Text
pResourceArn_,
      $sel:policy:CreateResourcePolicy' :: Text
policy = Text
pPolicy_
    }

-- | The Amazon Resource Name (ARN) of the bot or bot alias that the resource
-- policy is attached to.
createResourcePolicy_resourceArn :: Lens.Lens' CreateResourcePolicy Prelude.Text
createResourcePolicy_resourceArn :: Lens' CreateResourcePolicy Text
createResourcePolicy_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResourcePolicy' {Text
resourceArn :: Text
$sel:resourceArn:CreateResourcePolicy' :: CreateResourcePolicy -> Text
resourceArn} -> Text
resourceArn) (\s :: CreateResourcePolicy
s@CreateResourcePolicy' {} Text
a -> CreateResourcePolicy
s {$sel:resourceArn:CreateResourcePolicy' :: Text
resourceArn = Text
a} :: CreateResourcePolicy)

-- | A resource policy to add to the resource. The policy is a JSON structure
-- that contains one or more statements that define the policy. The policy
-- must follow the IAM syntax. For more information about the contents of a
-- JSON policy document, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html IAM JSON policy reference>
-- .
--
-- If the policy isn\'t valid, Amazon Lex returns a validation exception.
createResourcePolicy_policy :: Lens.Lens' CreateResourcePolicy Prelude.Text
createResourcePolicy_policy :: Lens' CreateResourcePolicy Text
createResourcePolicy_policy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResourcePolicy' {Text
policy :: Text
$sel:policy:CreateResourcePolicy' :: CreateResourcePolicy -> Text
policy} -> Text
policy) (\s :: CreateResourcePolicy
s@CreateResourcePolicy' {} Text
a -> CreateResourcePolicy
s {$sel:policy:CreateResourcePolicy' :: Text
policy = Text
a} :: CreateResourcePolicy)

instance Core.AWSRequest CreateResourcePolicy where
  type
    AWSResponse CreateResourcePolicy =
      CreateResourcePolicyResponse
  request :: (Service -> Service)
-> CreateResourcePolicy -> Request CreateResourcePolicy
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 CreateResourcePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateResourcePolicy)))
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 -> CreateResourcePolicyResponse
CreateResourcePolicyResponse'
            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
"resourceArn")
            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
"revisionId")
            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 CreateResourcePolicy where
  hashWithSalt :: Int -> CreateResourcePolicy -> Int
hashWithSalt Int
_salt CreateResourcePolicy' {Text
policy :: Text
resourceArn :: Text
$sel:policy:CreateResourcePolicy' :: CreateResourcePolicy -> Text
$sel:resourceArn:CreateResourcePolicy' :: CreateResourcePolicy -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policy

instance Prelude.NFData CreateResourcePolicy where
  rnf :: CreateResourcePolicy -> ()
rnf CreateResourcePolicy' {Text
policy :: Text
resourceArn :: Text
$sel:policy:CreateResourcePolicy' :: CreateResourcePolicy -> Text
$sel:resourceArn:CreateResourcePolicy' :: CreateResourcePolicy -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
resourceArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
policy

instance Data.ToHeaders CreateResourcePolicy where
  toHeaders :: CreateResourcePolicy -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateResourcePolicy where
  toJSON :: CreateResourcePolicy -> Value
toJSON CreateResourcePolicy' {Text
policy :: Text
resourceArn :: Text
$sel:policy:CreateResourcePolicy' :: CreateResourcePolicy -> Text
$sel:resourceArn:CreateResourcePolicy' :: CreateResourcePolicy -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"policy" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
policy)]
      )

instance Data.ToPath CreateResourcePolicy where
  toPath :: CreateResourcePolicy -> ByteString
toPath CreateResourcePolicy' {Text
policy :: Text
resourceArn :: Text
$sel:policy:CreateResourcePolicy' :: CreateResourcePolicy -> Text
$sel:resourceArn:CreateResourcePolicy' :: CreateResourcePolicy -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/policy/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
resourceArn, ByteString
"/"]

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

-- | /See:/ 'newCreateResourcePolicyResponse' smart constructor.
data CreateResourcePolicyResponse = CreateResourcePolicyResponse'
  { -- | The Amazon Resource Name (ARN) of the bot or bot alias that the resource
    -- policy was attached to.
    CreateResourcePolicyResponse -> Maybe Text
resourceArn :: Prelude.Maybe Prelude.Text,
    -- | The current revision of the resource policy. Use the revision ID to make
    -- sure that you are updating the most current version of a resource policy
    -- when you add a policy statement to a resource, delete a resource, or
    -- update a resource.
    CreateResourcePolicyResponse -> Maybe Text
revisionId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateResourcePolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateResourcePolicyResponse
-> CreateResourcePolicyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateResourcePolicyResponse
-> CreateResourcePolicyResponse -> Bool
$c/= :: CreateResourcePolicyResponse
-> CreateResourcePolicyResponse -> Bool
== :: CreateResourcePolicyResponse
-> CreateResourcePolicyResponse -> Bool
$c== :: CreateResourcePolicyResponse
-> CreateResourcePolicyResponse -> Bool
Prelude.Eq, ReadPrec [CreateResourcePolicyResponse]
ReadPrec CreateResourcePolicyResponse
Int -> ReadS CreateResourcePolicyResponse
ReadS [CreateResourcePolicyResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateResourcePolicyResponse]
$creadListPrec :: ReadPrec [CreateResourcePolicyResponse]
readPrec :: ReadPrec CreateResourcePolicyResponse
$creadPrec :: ReadPrec CreateResourcePolicyResponse
readList :: ReadS [CreateResourcePolicyResponse]
$creadList :: ReadS [CreateResourcePolicyResponse]
readsPrec :: Int -> ReadS CreateResourcePolicyResponse
$creadsPrec :: Int -> ReadS CreateResourcePolicyResponse
Prelude.Read, Int -> CreateResourcePolicyResponse -> ShowS
[CreateResourcePolicyResponse] -> ShowS
CreateResourcePolicyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateResourcePolicyResponse] -> ShowS
$cshowList :: [CreateResourcePolicyResponse] -> ShowS
show :: CreateResourcePolicyResponse -> String
$cshow :: CreateResourcePolicyResponse -> String
showsPrec :: Int -> CreateResourcePolicyResponse -> ShowS
$cshowsPrec :: Int -> CreateResourcePolicyResponse -> ShowS
Prelude.Show, forall x.
Rep CreateResourcePolicyResponse x -> CreateResourcePolicyResponse
forall x.
CreateResourcePolicyResponse -> Rep CreateResourcePolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateResourcePolicyResponse x -> CreateResourcePolicyResponse
$cfrom :: forall x.
CreateResourcePolicyResponse -> Rep CreateResourcePolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateResourcePolicyResponse' 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:
--
-- 'resourceArn', 'createResourcePolicyResponse_resourceArn' - The Amazon Resource Name (ARN) of the bot or bot alias that the resource
-- policy was attached to.
--
-- 'revisionId', 'createResourcePolicyResponse_revisionId' - The current revision of the resource policy. Use the revision ID to make
-- sure that you are updating the most current version of a resource policy
-- when you add a policy statement to a resource, delete a resource, or
-- update a resource.
--
-- 'httpStatus', 'createResourcePolicyResponse_httpStatus' - The response's http status code.
newCreateResourcePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateResourcePolicyResponse
newCreateResourcePolicyResponse :: Int -> CreateResourcePolicyResponse
newCreateResourcePolicyResponse Int
pHttpStatus_ =
  CreateResourcePolicyResponse'
    { $sel:resourceArn:CreateResourcePolicyResponse' :: Maybe Text
resourceArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:revisionId:CreateResourcePolicyResponse' :: Maybe Text
revisionId = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateResourcePolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the bot or bot alias that the resource
-- policy was attached to.
createResourcePolicyResponse_resourceArn :: Lens.Lens' CreateResourcePolicyResponse (Prelude.Maybe Prelude.Text)
createResourcePolicyResponse_resourceArn :: Lens' CreateResourcePolicyResponse (Maybe Text)
createResourcePolicyResponse_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResourcePolicyResponse' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:CreateResourcePolicyResponse' :: CreateResourcePolicyResponse -> Maybe Text
resourceArn} -> Maybe Text
resourceArn) (\s :: CreateResourcePolicyResponse
s@CreateResourcePolicyResponse' {} Maybe Text
a -> CreateResourcePolicyResponse
s {$sel:resourceArn:CreateResourcePolicyResponse' :: Maybe Text
resourceArn = Maybe Text
a} :: CreateResourcePolicyResponse)

-- | The current revision of the resource policy. Use the revision ID to make
-- sure that you are updating the most current version of a resource policy
-- when you add a policy statement to a resource, delete a resource, or
-- update a resource.
createResourcePolicyResponse_revisionId :: Lens.Lens' CreateResourcePolicyResponse (Prelude.Maybe Prelude.Text)
createResourcePolicyResponse_revisionId :: Lens' CreateResourcePolicyResponse (Maybe Text)
createResourcePolicyResponse_revisionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateResourcePolicyResponse' {Maybe Text
revisionId :: Maybe Text
$sel:revisionId:CreateResourcePolicyResponse' :: CreateResourcePolicyResponse -> Maybe Text
revisionId} -> Maybe Text
revisionId) (\s :: CreateResourcePolicyResponse
s@CreateResourcePolicyResponse' {} Maybe Text
a -> CreateResourcePolicyResponse
s {$sel:revisionId:CreateResourcePolicyResponse' :: Maybe Text
revisionId = Maybe Text
a} :: CreateResourcePolicyResponse)

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

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