{-# 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.SESV2.CreateEmailIdentityPolicy
-- 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 the specified sending authorization policy for the given
-- identity (an email address or a domain).
--
-- This API is for the identity owner only. If you have not verified the
-- identity, this API will return an error.
--
-- Sending authorization is a feature that enables an identity owner to
-- authorize other senders to use its identities. For information about
-- using sending authorization, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization.html Amazon SES Developer Guide>.
--
-- You can execute this operation no more than once per second.
module Amazonka.SESV2.CreateEmailIdentityPolicy
  ( -- * Creating a Request
    CreateEmailIdentityPolicy (..),
    newCreateEmailIdentityPolicy,

    -- * Request Lenses
    createEmailIdentityPolicy_emailIdentity,
    createEmailIdentityPolicy_policyName,
    createEmailIdentityPolicy_policy,

    -- * Destructuring the Response
    CreateEmailIdentityPolicyResponse (..),
    newCreateEmailIdentityPolicyResponse,

    -- * Response Lenses
    createEmailIdentityPolicyResponse_httpStatus,
  )
where

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
import Amazonka.SESV2.Types

-- | Represents a request to create a sending authorization policy for an
-- identity. Sending authorization is an Amazon SES feature that enables
-- you to authorize other senders to use your identities. For information,
-- see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization-identity-owner-tasks-management.html Amazon SES Developer Guide>.
--
-- /See:/ 'newCreateEmailIdentityPolicy' smart constructor.
data CreateEmailIdentityPolicy = CreateEmailIdentityPolicy'
  { -- | The email identity.
    CreateEmailIdentityPolicy -> Text
emailIdentity :: Prelude.Text,
    -- | The name of the policy.
    --
    -- The policy name cannot exceed 64 characters and can only include
    -- alphanumeric characters, dashes, and underscores.
    CreateEmailIdentityPolicy -> Text
policyName :: Prelude.Text,
    -- | The text of the policy in JSON format. The policy cannot exceed 4 KB.
    --
    -- For information about the syntax of sending authorization policies, see
    -- the
    -- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization-policies.html Amazon SES Developer Guide>.
    CreateEmailIdentityPolicy -> Text
policy :: Prelude.Text
  }
  deriving (CreateEmailIdentityPolicy -> CreateEmailIdentityPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateEmailIdentityPolicy -> CreateEmailIdentityPolicy -> Bool
$c/= :: CreateEmailIdentityPolicy -> CreateEmailIdentityPolicy -> Bool
== :: CreateEmailIdentityPolicy -> CreateEmailIdentityPolicy -> Bool
$c== :: CreateEmailIdentityPolicy -> CreateEmailIdentityPolicy -> Bool
Prelude.Eq, ReadPrec [CreateEmailIdentityPolicy]
ReadPrec CreateEmailIdentityPolicy
Int -> ReadS CreateEmailIdentityPolicy
ReadS [CreateEmailIdentityPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateEmailIdentityPolicy]
$creadListPrec :: ReadPrec [CreateEmailIdentityPolicy]
readPrec :: ReadPrec CreateEmailIdentityPolicy
$creadPrec :: ReadPrec CreateEmailIdentityPolicy
readList :: ReadS [CreateEmailIdentityPolicy]
$creadList :: ReadS [CreateEmailIdentityPolicy]
readsPrec :: Int -> ReadS CreateEmailIdentityPolicy
$creadsPrec :: Int -> ReadS CreateEmailIdentityPolicy
Prelude.Read, Int -> CreateEmailIdentityPolicy -> ShowS
[CreateEmailIdentityPolicy] -> ShowS
CreateEmailIdentityPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateEmailIdentityPolicy] -> ShowS
$cshowList :: [CreateEmailIdentityPolicy] -> ShowS
show :: CreateEmailIdentityPolicy -> String
$cshow :: CreateEmailIdentityPolicy -> String
showsPrec :: Int -> CreateEmailIdentityPolicy -> ShowS
$cshowsPrec :: Int -> CreateEmailIdentityPolicy -> ShowS
Prelude.Show, forall x.
Rep CreateEmailIdentityPolicy x -> CreateEmailIdentityPolicy
forall x.
CreateEmailIdentityPolicy -> Rep CreateEmailIdentityPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateEmailIdentityPolicy x -> CreateEmailIdentityPolicy
$cfrom :: forall x.
CreateEmailIdentityPolicy -> Rep CreateEmailIdentityPolicy x
Prelude.Generic)

-- |
-- Create a value of 'CreateEmailIdentityPolicy' 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:
--
-- 'emailIdentity', 'createEmailIdentityPolicy_emailIdentity' - The email identity.
--
-- 'policyName', 'createEmailIdentityPolicy_policyName' - The name of the policy.
--
-- The policy name cannot exceed 64 characters and can only include
-- alphanumeric characters, dashes, and underscores.
--
-- 'policy', 'createEmailIdentityPolicy_policy' - The text of the policy in JSON format. The policy cannot exceed 4 KB.
--
-- For information about the syntax of sending authorization policies, see
-- the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization-policies.html Amazon SES Developer Guide>.
newCreateEmailIdentityPolicy ::
  -- | 'emailIdentity'
  Prelude.Text ->
  -- | 'policyName'
  Prelude.Text ->
  -- | 'policy'
  Prelude.Text ->
  CreateEmailIdentityPolicy
newCreateEmailIdentityPolicy :: Text -> Text -> Text -> CreateEmailIdentityPolicy
newCreateEmailIdentityPolicy
  Text
pEmailIdentity_
  Text
pPolicyName_
  Text
pPolicy_ =
    CreateEmailIdentityPolicy'
      { $sel:emailIdentity:CreateEmailIdentityPolicy' :: Text
emailIdentity =
          Text
pEmailIdentity_,
        $sel:policyName:CreateEmailIdentityPolicy' :: Text
policyName = Text
pPolicyName_,
        $sel:policy:CreateEmailIdentityPolicy' :: Text
policy = Text
pPolicy_
      }

-- | The email identity.
createEmailIdentityPolicy_emailIdentity :: Lens.Lens' CreateEmailIdentityPolicy Prelude.Text
createEmailIdentityPolicy_emailIdentity :: Lens' CreateEmailIdentityPolicy Text
createEmailIdentityPolicy_emailIdentity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEmailIdentityPolicy' {Text
emailIdentity :: Text
$sel:emailIdentity:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
emailIdentity} -> Text
emailIdentity) (\s :: CreateEmailIdentityPolicy
s@CreateEmailIdentityPolicy' {} Text
a -> CreateEmailIdentityPolicy
s {$sel:emailIdentity:CreateEmailIdentityPolicy' :: Text
emailIdentity = Text
a} :: CreateEmailIdentityPolicy)

-- | The name of the policy.
--
-- The policy name cannot exceed 64 characters and can only include
-- alphanumeric characters, dashes, and underscores.
createEmailIdentityPolicy_policyName :: Lens.Lens' CreateEmailIdentityPolicy Prelude.Text
createEmailIdentityPolicy_policyName :: Lens' CreateEmailIdentityPolicy Text
createEmailIdentityPolicy_policyName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEmailIdentityPolicy' {Text
policyName :: Text
$sel:policyName:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
policyName} -> Text
policyName) (\s :: CreateEmailIdentityPolicy
s@CreateEmailIdentityPolicy' {} Text
a -> CreateEmailIdentityPolicy
s {$sel:policyName:CreateEmailIdentityPolicy' :: Text
policyName = Text
a} :: CreateEmailIdentityPolicy)

-- | The text of the policy in JSON format. The policy cannot exceed 4 KB.
--
-- For information about the syntax of sending authorization policies, see
-- the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-authorization-policies.html Amazon SES Developer Guide>.
createEmailIdentityPolicy_policy :: Lens.Lens' CreateEmailIdentityPolicy Prelude.Text
createEmailIdentityPolicy_policy :: Lens' CreateEmailIdentityPolicy Text
createEmailIdentityPolicy_policy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateEmailIdentityPolicy' {Text
policy :: Text
$sel:policy:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
policy} -> Text
policy) (\s :: CreateEmailIdentityPolicy
s@CreateEmailIdentityPolicy' {} Text
a -> CreateEmailIdentityPolicy
s {$sel:policy:CreateEmailIdentityPolicy' :: Text
policy = Text
a} :: CreateEmailIdentityPolicy)

instance Core.AWSRequest CreateEmailIdentityPolicy where
  type
    AWSResponse CreateEmailIdentityPolicy =
      CreateEmailIdentityPolicyResponse
  request :: (Service -> Service)
-> CreateEmailIdentityPolicy -> Request CreateEmailIdentityPolicy
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 CreateEmailIdentityPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateEmailIdentityPolicy)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CreateEmailIdentityPolicyResponse
CreateEmailIdentityPolicyResponse'
            forall (f :: * -> *) a b. Functor 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 CreateEmailIdentityPolicy where
  hashWithSalt :: Int -> CreateEmailIdentityPolicy -> Int
hashWithSalt Int
_salt CreateEmailIdentityPolicy' {Text
policy :: Text
policyName :: Text
emailIdentity :: Text
$sel:policy:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
$sel:policyName:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
$sel:emailIdentity:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
emailIdentity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policyName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policy

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

instance Data.ToHeaders CreateEmailIdentityPolicy where
  toHeaders :: CreateEmailIdentityPolicy -> 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 CreateEmailIdentityPolicy where
  toJSON :: CreateEmailIdentityPolicy -> Value
toJSON CreateEmailIdentityPolicy' {Text
policy :: Text
policyName :: Text
emailIdentity :: Text
$sel:policy:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
$sel:policyName:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
$sel:emailIdentity:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> 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 CreateEmailIdentityPolicy where
  toPath :: CreateEmailIdentityPolicy -> ByteString
toPath CreateEmailIdentityPolicy' {Text
policy :: Text
policyName :: Text
emailIdentity :: Text
$sel:policy:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
$sel:policyName:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
$sel:emailIdentity:CreateEmailIdentityPolicy' :: CreateEmailIdentityPolicy -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/v2/email/identities/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
emailIdentity,
        ByteString
"/policies/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
policyName
      ]

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

-- | An HTTP 200 response if the request succeeds, or an error message if the
-- request fails.
--
-- /See:/ 'newCreateEmailIdentityPolicyResponse' smart constructor.
data CreateEmailIdentityPolicyResponse = CreateEmailIdentityPolicyResponse'
  { -- | The response's http status code.
    CreateEmailIdentityPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateEmailIdentityPolicyResponse
-> CreateEmailIdentityPolicyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateEmailIdentityPolicyResponse
-> CreateEmailIdentityPolicyResponse -> Bool
$c/= :: CreateEmailIdentityPolicyResponse
-> CreateEmailIdentityPolicyResponse -> Bool
== :: CreateEmailIdentityPolicyResponse
-> CreateEmailIdentityPolicyResponse -> Bool
$c== :: CreateEmailIdentityPolicyResponse
-> CreateEmailIdentityPolicyResponse -> Bool
Prelude.Eq, ReadPrec [CreateEmailIdentityPolicyResponse]
ReadPrec CreateEmailIdentityPolicyResponse
Int -> ReadS CreateEmailIdentityPolicyResponse
ReadS [CreateEmailIdentityPolicyResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateEmailIdentityPolicyResponse]
$creadListPrec :: ReadPrec [CreateEmailIdentityPolicyResponse]
readPrec :: ReadPrec CreateEmailIdentityPolicyResponse
$creadPrec :: ReadPrec CreateEmailIdentityPolicyResponse
readList :: ReadS [CreateEmailIdentityPolicyResponse]
$creadList :: ReadS [CreateEmailIdentityPolicyResponse]
readsPrec :: Int -> ReadS CreateEmailIdentityPolicyResponse
$creadsPrec :: Int -> ReadS CreateEmailIdentityPolicyResponse
Prelude.Read, Int -> CreateEmailIdentityPolicyResponse -> ShowS
[CreateEmailIdentityPolicyResponse] -> ShowS
CreateEmailIdentityPolicyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateEmailIdentityPolicyResponse] -> ShowS
$cshowList :: [CreateEmailIdentityPolicyResponse] -> ShowS
show :: CreateEmailIdentityPolicyResponse -> String
$cshow :: CreateEmailIdentityPolicyResponse -> String
showsPrec :: Int -> CreateEmailIdentityPolicyResponse -> ShowS
$cshowsPrec :: Int -> CreateEmailIdentityPolicyResponse -> ShowS
Prelude.Show, forall x.
Rep CreateEmailIdentityPolicyResponse x
-> CreateEmailIdentityPolicyResponse
forall x.
CreateEmailIdentityPolicyResponse
-> Rep CreateEmailIdentityPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateEmailIdentityPolicyResponse x
-> CreateEmailIdentityPolicyResponse
$cfrom :: forall x.
CreateEmailIdentityPolicyResponse
-> Rep CreateEmailIdentityPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateEmailIdentityPolicyResponse' 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:
--
-- 'httpStatus', 'createEmailIdentityPolicyResponse_httpStatus' - The response's http status code.
newCreateEmailIdentityPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateEmailIdentityPolicyResponse
newCreateEmailIdentityPolicyResponse :: Int -> CreateEmailIdentityPolicyResponse
newCreateEmailIdentityPolicyResponse Int
pHttpStatus_ =
  CreateEmailIdentityPolicyResponse'
    { $sel:httpStatus:CreateEmailIdentityPolicyResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance
  Prelude.NFData
    CreateEmailIdentityPolicyResponse
  where
  rnf :: CreateEmailIdentityPolicyResponse -> ()
rnf CreateEmailIdentityPolicyResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateEmailIdentityPolicyResponse' :: CreateEmailIdentityPolicyResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus