{-# 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.UpdateEmailIdentityPolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates the specified sending authorization policy for the given
-- identity (an email address or a domain). This API returns successfully
-- even if a policy with the specified name does not exist.
--
-- 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.UpdateEmailIdentityPolicy
  ( -- * Creating a Request
    UpdateEmailIdentityPolicy (..),
    newUpdateEmailIdentityPolicy,

    -- * Request Lenses
    updateEmailIdentityPolicy_emailIdentity,
    updateEmailIdentityPolicy_policyName,
    updateEmailIdentityPolicy_policy,

    -- * Destructuring the Response
    UpdateEmailIdentityPolicyResponse (..),
    newUpdateEmailIdentityPolicyResponse,

    -- * Response Lenses
    updateEmailIdentityPolicyResponse_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 update 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:/ 'newUpdateEmailIdentityPolicy' smart constructor.
data UpdateEmailIdentityPolicy = UpdateEmailIdentityPolicy'
  { -- | The email identity.
    UpdateEmailIdentityPolicy -> 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.
    UpdateEmailIdentityPolicy -> 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>.
    UpdateEmailIdentityPolicy -> Text
policy :: Prelude.Text
  }
  deriving (UpdateEmailIdentityPolicy -> UpdateEmailIdentityPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateEmailIdentityPolicy -> UpdateEmailIdentityPolicy -> Bool
$c/= :: UpdateEmailIdentityPolicy -> UpdateEmailIdentityPolicy -> Bool
== :: UpdateEmailIdentityPolicy -> UpdateEmailIdentityPolicy -> Bool
$c== :: UpdateEmailIdentityPolicy -> UpdateEmailIdentityPolicy -> Bool
Prelude.Eq, ReadPrec [UpdateEmailIdentityPolicy]
ReadPrec UpdateEmailIdentityPolicy
Int -> ReadS UpdateEmailIdentityPolicy
ReadS [UpdateEmailIdentityPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateEmailIdentityPolicy]
$creadListPrec :: ReadPrec [UpdateEmailIdentityPolicy]
readPrec :: ReadPrec UpdateEmailIdentityPolicy
$creadPrec :: ReadPrec UpdateEmailIdentityPolicy
readList :: ReadS [UpdateEmailIdentityPolicy]
$creadList :: ReadS [UpdateEmailIdentityPolicy]
readsPrec :: Int -> ReadS UpdateEmailIdentityPolicy
$creadsPrec :: Int -> ReadS UpdateEmailIdentityPolicy
Prelude.Read, Int -> UpdateEmailIdentityPolicy -> ShowS
[UpdateEmailIdentityPolicy] -> ShowS
UpdateEmailIdentityPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateEmailIdentityPolicy] -> ShowS
$cshowList :: [UpdateEmailIdentityPolicy] -> ShowS
show :: UpdateEmailIdentityPolicy -> String
$cshow :: UpdateEmailIdentityPolicy -> String
showsPrec :: Int -> UpdateEmailIdentityPolicy -> ShowS
$cshowsPrec :: Int -> UpdateEmailIdentityPolicy -> ShowS
Prelude.Show, forall x.
Rep UpdateEmailIdentityPolicy x -> UpdateEmailIdentityPolicy
forall x.
UpdateEmailIdentityPolicy -> Rep UpdateEmailIdentityPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateEmailIdentityPolicy x -> UpdateEmailIdentityPolicy
$cfrom :: forall x.
UpdateEmailIdentityPolicy -> Rep UpdateEmailIdentityPolicy x
Prelude.Generic)

-- |
-- Create a value of 'UpdateEmailIdentityPolicy' 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', 'updateEmailIdentityPolicy_emailIdentity' - The email identity.
--
-- 'policyName', 'updateEmailIdentityPolicy_policyName' - The name of the policy.
--
-- The policy name cannot exceed 64 characters and can only include
-- alphanumeric characters, dashes, and underscores.
--
-- 'policy', 'updateEmailIdentityPolicy_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>.
newUpdateEmailIdentityPolicy ::
  -- | 'emailIdentity'
  Prelude.Text ->
  -- | 'policyName'
  Prelude.Text ->
  -- | 'policy'
  Prelude.Text ->
  UpdateEmailIdentityPolicy
newUpdateEmailIdentityPolicy :: Text -> Text -> Text -> UpdateEmailIdentityPolicy
newUpdateEmailIdentityPolicy
  Text
pEmailIdentity_
  Text
pPolicyName_
  Text
pPolicy_ =
    UpdateEmailIdentityPolicy'
      { $sel:emailIdentity:UpdateEmailIdentityPolicy' :: Text
emailIdentity =
          Text
pEmailIdentity_,
        $sel:policyName:UpdateEmailIdentityPolicy' :: Text
policyName = Text
pPolicyName_,
        $sel:policy:UpdateEmailIdentityPolicy' :: Text
policy = Text
pPolicy_
      }

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

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

-- | 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>.
updateEmailIdentityPolicy_policy :: Lens.Lens' UpdateEmailIdentityPolicy Prelude.Text
updateEmailIdentityPolicy_policy :: Lens' UpdateEmailIdentityPolicy Text
updateEmailIdentityPolicy_policy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateEmailIdentityPolicy' {Text
policy :: Text
$sel:policy:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
policy} -> Text
policy) (\s :: UpdateEmailIdentityPolicy
s@UpdateEmailIdentityPolicy' {} Text
a -> UpdateEmailIdentityPolicy
s {$sel:policy:UpdateEmailIdentityPolicy' :: Text
policy = Text
a} :: UpdateEmailIdentityPolicy)

instance Core.AWSRequest UpdateEmailIdentityPolicy where
  type
    AWSResponse UpdateEmailIdentityPolicy =
      UpdateEmailIdentityPolicyResponse
  request :: (Service -> Service)
-> UpdateEmailIdentityPolicy -> Request UpdateEmailIdentityPolicy
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 UpdateEmailIdentityPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateEmailIdentityPolicy)))
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 -> UpdateEmailIdentityPolicyResponse
UpdateEmailIdentityPolicyResponse'
            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 UpdateEmailIdentityPolicy where
  hashWithSalt :: Int -> UpdateEmailIdentityPolicy -> Int
hashWithSalt Int
_salt UpdateEmailIdentityPolicy' {Text
policy :: Text
policyName :: Text
emailIdentity :: Text
$sel:policy:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
$sel:policyName:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
$sel:emailIdentity:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> 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 UpdateEmailIdentityPolicy where
  rnf :: UpdateEmailIdentityPolicy -> ()
rnf UpdateEmailIdentityPolicy' {Text
policy :: Text
policyName :: Text
emailIdentity :: Text
$sel:policy:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
$sel:policyName:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
$sel:emailIdentity:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> 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 UpdateEmailIdentityPolicy where
  toHeaders :: UpdateEmailIdentityPolicy -> 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 UpdateEmailIdentityPolicy where
  toJSON :: UpdateEmailIdentityPolicy -> Value
toJSON UpdateEmailIdentityPolicy' {Text
policy :: Text
policyName :: Text
emailIdentity :: Text
$sel:policy:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
$sel:policyName:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
$sel:emailIdentity:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> 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 UpdateEmailIdentityPolicy where
  toPath :: UpdateEmailIdentityPolicy -> ByteString
toPath UpdateEmailIdentityPolicy' {Text
policy :: Text
policyName :: Text
emailIdentity :: Text
$sel:policy:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
$sel:policyName:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> Text
$sel:emailIdentity:UpdateEmailIdentityPolicy' :: UpdateEmailIdentityPolicy -> 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 UpdateEmailIdentityPolicy where
  toQuery :: UpdateEmailIdentityPolicy -> 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:/ 'newUpdateEmailIdentityPolicyResponse' smart constructor.
data UpdateEmailIdentityPolicyResponse = UpdateEmailIdentityPolicyResponse'
  { -- | The response's http status code.
    UpdateEmailIdentityPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateEmailIdentityPolicyResponse
-> UpdateEmailIdentityPolicyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateEmailIdentityPolicyResponse
-> UpdateEmailIdentityPolicyResponse -> Bool
$c/= :: UpdateEmailIdentityPolicyResponse
-> UpdateEmailIdentityPolicyResponse -> Bool
== :: UpdateEmailIdentityPolicyResponse
-> UpdateEmailIdentityPolicyResponse -> Bool
$c== :: UpdateEmailIdentityPolicyResponse
-> UpdateEmailIdentityPolicyResponse -> Bool
Prelude.Eq, ReadPrec [UpdateEmailIdentityPolicyResponse]
ReadPrec UpdateEmailIdentityPolicyResponse
Int -> ReadS UpdateEmailIdentityPolicyResponse
ReadS [UpdateEmailIdentityPolicyResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateEmailIdentityPolicyResponse]
$creadListPrec :: ReadPrec [UpdateEmailIdentityPolicyResponse]
readPrec :: ReadPrec UpdateEmailIdentityPolicyResponse
$creadPrec :: ReadPrec UpdateEmailIdentityPolicyResponse
readList :: ReadS [UpdateEmailIdentityPolicyResponse]
$creadList :: ReadS [UpdateEmailIdentityPolicyResponse]
readsPrec :: Int -> ReadS UpdateEmailIdentityPolicyResponse
$creadsPrec :: Int -> ReadS UpdateEmailIdentityPolicyResponse
Prelude.Read, Int -> UpdateEmailIdentityPolicyResponse -> ShowS
[UpdateEmailIdentityPolicyResponse] -> ShowS
UpdateEmailIdentityPolicyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateEmailIdentityPolicyResponse] -> ShowS
$cshowList :: [UpdateEmailIdentityPolicyResponse] -> ShowS
show :: UpdateEmailIdentityPolicyResponse -> String
$cshow :: UpdateEmailIdentityPolicyResponse -> String
showsPrec :: Int -> UpdateEmailIdentityPolicyResponse -> ShowS
$cshowsPrec :: Int -> UpdateEmailIdentityPolicyResponse -> ShowS
Prelude.Show, forall x.
Rep UpdateEmailIdentityPolicyResponse x
-> UpdateEmailIdentityPolicyResponse
forall x.
UpdateEmailIdentityPolicyResponse
-> Rep UpdateEmailIdentityPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateEmailIdentityPolicyResponse x
-> UpdateEmailIdentityPolicyResponse
$cfrom :: forall x.
UpdateEmailIdentityPolicyResponse
-> Rep UpdateEmailIdentityPolicyResponse x
Prelude.Generic)

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

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

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