{-# 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.GetEmailIdentityPolicies
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns the requested sending authorization policies for the given
-- identity (an email address or a domain). The policies are returned as a
-- map of policy names to policy contents. You can retrieve a maximum of 20
-- policies at a time.
--
-- 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.GetEmailIdentityPolicies
  ( -- * Creating a Request
    GetEmailIdentityPolicies (..),
    newGetEmailIdentityPolicies,

    -- * Request Lenses
    getEmailIdentityPolicies_emailIdentity,

    -- * Destructuring the Response
    GetEmailIdentityPoliciesResponse (..),
    newGetEmailIdentityPoliciesResponse,

    -- * Response Lenses
    getEmailIdentityPoliciesResponse_policies,
    getEmailIdentityPoliciesResponse_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

-- | A request to return the policies of an email identity.
--
-- /See:/ 'newGetEmailIdentityPolicies' smart constructor.
data GetEmailIdentityPolicies = GetEmailIdentityPolicies'
  { -- | The email identity.
    GetEmailIdentityPolicies -> Text
emailIdentity :: Prelude.Text
  }
  deriving (GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
$c/= :: GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
== :: GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
$c== :: GetEmailIdentityPolicies -> GetEmailIdentityPolicies -> Bool
Prelude.Eq, ReadPrec [GetEmailIdentityPolicies]
ReadPrec GetEmailIdentityPolicies
Int -> ReadS GetEmailIdentityPolicies
ReadS [GetEmailIdentityPolicies]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEmailIdentityPolicies]
$creadListPrec :: ReadPrec [GetEmailIdentityPolicies]
readPrec :: ReadPrec GetEmailIdentityPolicies
$creadPrec :: ReadPrec GetEmailIdentityPolicies
readList :: ReadS [GetEmailIdentityPolicies]
$creadList :: ReadS [GetEmailIdentityPolicies]
readsPrec :: Int -> ReadS GetEmailIdentityPolicies
$creadsPrec :: Int -> ReadS GetEmailIdentityPolicies
Prelude.Read, Int -> GetEmailIdentityPolicies -> ShowS
[GetEmailIdentityPolicies] -> ShowS
GetEmailIdentityPolicies -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEmailIdentityPolicies] -> ShowS
$cshowList :: [GetEmailIdentityPolicies] -> ShowS
show :: GetEmailIdentityPolicies -> String
$cshow :: GetEmailIdentityPolicies -> String
showsPrec :: Int -> GetEmailIdentityPolicies -> ShowS
$cshowsPrec :: Int -> GetEmailIdentityPolicies -> ShowS
Prelude.Show, forall x.
Rep GetEmailIdentityPolicies x -> GetEmailIdentityPolicies
forall x.
GetEmailIdentityPolicies -> Rep GetEmailIdentityPolicies x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetEmailIdentityPolicies x -> GetEmailIdentityPolicies
$cfrom :: forall x.
GetEmailIdentityPolicies -> Rep GetEmailIdentityPolicies x
Prelude.Generic)

-- |
-- Create a value of 'GetEmailIdentityPolicies' 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', 'getEmailIdentityPolicies_emailIdentity' - The email identity.
newGetEmailIdentityPolicies ::
  -- | 'emailIdentity'
  Prelude.Text ->
  GetEmailIdentityPolicies
newGetEmailIdentityPolicies :: Text -> GetEmailIdentityPolicies
newGetEmailIdentityPolicies Text
pEmailIdentity_ =
  GetEmailIdentityPolicies'
    { $sel:emailIdentity:GetEmailIdentityPolicies' :: Text
emailIdentity =
        Text
pEmailIdentity_
    }

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

instance Core.AWSRequest GetEmailIdentityPolicies where
  type
    AWSResponse GetEmailIdentityPolicies =
      GetEmailIdentityPoliciesResponse
  request :: (Service -> Service)
-> GetEmailIdentityPolicies -> Request GetEmailIdentityPolicies
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetEmailIdentityPolicies
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetEmailIdentityPolicies)))
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 (HashMap Text Text)
-> Int -> GetEmailIdentityPoliciesResponse
GetEmailIdentityPoliciesResponse'
            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
"Policies" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            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 GetEmailIdentityPolicies where
  hashWithSalt :: Int -> GetEmailIdentityPolicies -> Int
hashWithSalt Int
_salt GetEmailIdentityPolicies' {Text
emailIdentity :: Text
$sel:emailIdentity:GetEmailIdentityPolicies' :: GetEmailIdentityPolicies -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
emailIdentity

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

instance Data.ToHeaders GetEmailIdentityPolicies where
  toHeaders :: GetEmailIdentityPolicies -> 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.ToPath GetEmailIdentityPolicies where
  toPath :: GetEmailIdentityPolicies -> ByteString
toPath GetEmailIdentityPolicies' {Text
emailIdentity :: Text
$sel:emailIdentity:GetEmailIdentityPolicies' :: GetEmailIdentityPolicies -> 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"
      ]

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

-- | Identity policies associated with email identity.
--
-- /See:/ 'newGetEmailIdentityPoliciesResponse' smart constructor.
data GetEmailIdentityPoliciesResponse = GetEmailIdentityPoliciesResponse'
  { -- | A map of policy names to policies.
    GetEmailIdentityPoliciesResponse -> Maybe (HashMap Text Text)
policies :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The response's http status code.
    GetEmailIdentityPoliciesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
$c/= :: GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
== :: GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
$c== :: GetEmailIdentityPoliciesResponse
-> GetEmailIdentityPoliciesResponse -> Bool
Prelude.Eq, ReadPrec [GetEmailIdentityPoliciesResponse]
ReadPrec GetEmailIdentityPoliciesResponse
Int -> ReadS GetEmailIdentityPoliciesResponse
ReadS [GetEmailIdentityPoliciesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetEmailIdentityPoliciesResponse]
$creadListPrec :: ReadPrec [GetEmailIdentityPoliciesResponse]
readPrec :: ReadPrec GetEmailIdentityPoliciesResponse
$creadPrec :: ReadPrec GetEmailIdentityPoliciesResponse
readList :: ReadS [GetEmailIdentityPoliciesResponse]
$creadList :: ReadS [GetEmailIdentityPoliciesResponse]
readsPrec :: Int -> ReadS GetEmailIdentityPoliciesResponse
$creadsPrec :: Int -> ReadS GetEmailIdentityPoliciesResponse
Prelude.Read, Int -> GetEmailIdentityPoliciesResponse -> ShowS
[GetEmailIdentityPoliciesResponse] -> ShowS
GetEmailIdentityPoliciesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetEmailIdentityPoliciesResponse] -> ShowS
$cshowList :: [GetEmailIdentityPoliciesResponse] -> ShowS
show :: GetEmailIdentityPoliciesResponse -> String
$cshow :: GetEmailIdentityPoliciesResponse -> String
showsPrec :: Int -> GetEmailIdentityPoliciesResponse -> ShowS
$cshowsPrec :: Int -> GetEmailIdentityPoliciesResponse -> ShowS
Prelude.Show, forall x.
Rep GetEmailIdentityPoliciesResponse x
-> GetEmailIdentityPoliciesResponse
forall x.
GetEmailIdentityPoliciesResponse
-> Rep GetEmailIdentityPoliciesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetEmailIdentityPoliciesResponse x
-> GetEmailIdentityPoliciesResponse
$cfrom :: forall x.
GetEmailIdentityPoliciesResponse
-> Rep GetEmailIdentityPoliciesResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetEmailIdentityPoliciesResponse' 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:
--
-- 'policies', 'getEmailIdentityPoliciesResponse_policies' - A map of policy names to policies.
--
-- 'httpStatus', 'getEmailIdentityPoliciesResponse_httpStatus' - The response's http status code.
newGetEmailIdentityPoliciesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetEmailIdentityPoliciesResponse
newGetEmailIdentityPoliciesResponse :: Int -> GetEmailIdentityPoliciesResponse
newGetEmailIdentityPoliciesResponse Int
pHttpStatus_ =
  GetEmailIdentityPoliciesResponse'
    { $sel:policies:GetEmailIdentityPoliciesResponse' :: Maybe (HashMap Text Text)
policies =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetEmailIdentityPoliciesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A map of policy names to policies.
getEmailIdentityPoliciesResponse_policies :: Lens.Lens' GetEmailIdentityPoliciesResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
getEmailIdentityPoliciesResponse_policies :: Lens' GetEmailIdentityPoliciesResponse (Maybe (HashMap Text Text))
getEmailIdentityPoliciesResponse_policies = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetEmailIdentityPoliciesResponse' {Maybe (HashMap Text Text)
policies :: Maybe (HashMap Text Text)
$sel:policies:GetEmailIdentityPoliciesResponse' :: GetEmailIdentityPoliciesResponse -> Maybe (HashMap Text Text)
policies} -> Maybe (HashMap Text Text)
policies) (\s :: GetEmailIdentityPoliciesResponse
s@GetEmailIdentityPoliciesResponse' {} Maybe (HashMap Text Text)
a -> GetEmailIdentityPoliciesResponse
s {$sel:policies:GetEmailIdentityPoliciesResponse' :: Maybe (HashMap Text Text)
policies = Maybe (HashMap Text Text)
a} :: GetEmailIdentityPoliciesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

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