{-# 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.Organizations.ListPoliciesForTarget
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists the policies that are directly attached to the specified target
-- root, organizational unit (OU), or account. You must specify the policy
-- type that you want included in the returned list.
--
-- Always check the @NextToken@ response parameter for a @null@ value when
-- calling a @List*@ operation. These operations can occasionally return an
-- empty set of results even when there are more results available. The
-- @NextToken@ response parameter value is @null@ /only/ when there are no
-- more results to display.
--
-- This operation can be called only from the organization\'s management
-- account or by a member account that is a delegated administrator for an
-- Amazon Web Services service.
--
-- This operation returns paginated results.
module Amazonka.Organizations.ListPoliciesForTarget
  ( -- * Creating a Request
    ListPoliciesForTarget (..),
    newListPoliciesForTarget,

    -- * Request Lenses
    listPoliciesForTarget_maxResults,
    listPoliciesForTarget_nextToken,
    listPoliciesForTarget_targetId,
    listPoliciesForTarget_filter,

    -- * Destructuring the Response
    ListPoliciesForTargetResponse (..),
    newListPoliciesForTargetResponse,

    -- * Response Lenses
    listPoliciesForTargetResponse_nextToken,
    listPoliciesForTargetResponse_policies,
    listPoliciesForTargetResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListPoliciesForTarget' smart constructor.
data ListPoliciesForTarget = ListPoliciesForTarget'
  { -- | The total number of results that you want included on each page of the
    -- response. If you do not include this parameter, it defaults to a value
    -- that is specific to the operation. If additional items exist beyond the
    -- maximum you specify, the @NextToken@ response element is present and has
    -- a value (is not null). Include that value as the @NextToken@ request
    -- parameter in the next call to the operation to get the next part of the
    -- results. Note that Organizations might return fewer results than the
    -- maximum even when there are more results available. You should check
    -- @NextToken@ after every operation to ensure that you receive all of the
    -- results.
    ListPoliciesForTarget -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The parameter for receiving additional results if you receive a
    -- @NextToken@ response in a previous request. A @NextToken@ response
    -- indicates that more output is available. Set this parameter to the value
    -- of the previous call\'s @NextToken@ response to indicate where the
    -- output should continue from.
    ListPoliciesForTarget -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier (ID) of the root, organizational unit, or account
    -- whose policies you want to list.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for a target ID
    -- string requires one of the following:
    --
    -- -   __Root__ - A string that begins with \"r-\" followed by from 4 to 32
    --     lowercase letters or digits.
    --
    -- -   __Account__ - A string that consists of exactly 12 digits.
    --
    -- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
    --     followed by from 4 to 32 lowercase letters or digits (the ID of the
    --     root that the OU is in). This string is followed by a second \"-\"
    --     dash and from 8 to 32 additional lowercase letters or digits.
    ListPoliciesForTarget -> Text
targetId :: Prelude.Text,
    -- | The type of policy that you want to include in the returned list. You
    -- must specify one of the following values:
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
    ListPoliciesForTarget -> PolicyType
filter' :: PolicyType
  }
  deriving (ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
$c/= :: ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
== :: ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
$c== :: ListPoliciesForTarget -> ListPoliciesForTarget -> Bool
Prelude.Eq, ReadPrec [ListPoliciesForTarget]
ReadPrec ListPoliciesForTarget
Int -> ReadS ListPoliciesForTarget
ReadS [ListPoliciesForTarget]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPoliciesForTarget]
$creadListPrec :: ReadPrec [ListPoliciesForTarget]
readPrec :: ReadPrec ListPoliciesForTarget
$creadPrec :: ReadPrec ListPoliciesForTarget
readList :: ReadS [ListPoliciesForTarget]
$creadList :: ReadS [ListPoliciesForTarget]
readsPrec :: Int -> ReadS ListPoliciesForTarget
$creadsPrec :: Int -> ReadS ListPoliciesForTarget
Prelude.Read, Int -> ListPoliciesForTarget -> ShowS
[ListPoliciesForTarget] -> ShowS
ListPoliciesForTarget -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPoliciesForTarget] -> ShowS
$cshowList :: [ListPoliciesForTarget] -> ShowS
show :: ListPoliciesForTarget -> String
$cshow :: ListPoliciesForTarget -> String
showsPrec :: Int -> ListPoliciesForTarget -> ShowS
$cshowsPrec :: Int -> ListPoliciesForTarget -> ShowS
Prelude.Show, forall x. Rep ListPoliciesForTarget x -> ListPoliciesForTarget
forall x. ListPoliciesForTarget -> Rep ListPoliciesForTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListPoliciesForTarget x -> ListPoliciesForTarget
$cfrom :: forall x. ListPoliciesForTarget -> Rep ListPoliciesForTarget x
Prelude.Generic)

-- |
-- Create a value of 'ListPoliciesForTarget' 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:
--
-- 'maxResults', 'listPoliciesForTarget_maxResults' - The total number of results that you want included on each page of the
-- response. If you do not include this parameter, it defaults to a value
-- that is specific to the operation. If additional items exist beyond the
-- maximum you specify, the @NextToken@ response element is present and has
-- a value (is not null). Include that value as the @NextToken@ request
-- parameter in the next call to the operation to get the next part of the
-- results. Note that Organizations might return fewer results than the
-- maximum even when there are more results available. You should check
-- @NextToken@ after every operation to ensure that you receive all of the
-- results.
--
-- 'nextToken', 'listPoliciesForTarget_nextToken' - The parameter for receiving additional results if you receive a
-- @NextToken@ response in a previous request. A @NextToken@ response
-- indicates that more output is available. Set this parameter to the value
-- of the previous call\'s @NextToken@ response to indicate where the
-- output should continue from.
--
-- 'targetId', 'listPoliciesForTarget_targetId' - The unique identifier (ID) of the root, organizational unit, or account
-- whose policies you want to list.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a target ID
-- string requires one of the following:
--
-- -   __Root__ - A string that begins with \"r-\" followed by from 4 to 32
--     lowercase letters or digits.
--
-- -   __Account__ - A string that consists of exactly 12 digits.
--
-- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
--     followed by from 4 to 32 lowercase letters or digits (the ID of the
--     root that the OU is in). This string is followed by a second \"-\"
--     dash and from 8 to 32 additional lowercase letters or digits.
--
-- 'filter'', 'listPoliciesForTarget_filter' - The type of policy that you want to include in the returned list. You
-- must specify one of the following values:
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
newListPoliciesForTarget ::
  -- | 'targetId'
  Prelude.Text ->
  -- | 'filter''
  PolicyType ->
  ListPoliciesForTarget
newListPoliciesForTarget :: Text -> PolicyType -> ListPoliciesForTarget
newListPoliciesForTarget Text
pTargetId_ PolicyType
pFilter_ =
  ListPoliciesForTarget'
    { $sel:maxResults:ListPoliciesForTarget' :: Maybe Natural
maxResults =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListPoliciesForTarget' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:targetId:ListPoliciesForTarget' :: Text
targetId = Text
pTargetId_,
      $sel:filter':ListPoliciesForTarget' :: PolicyType
filter' = PolicyType
pFilter_
    }

-- | The total number of results that you want included on each page of the
-- response. If you do not include this parameter, it defaults to a value
-- that is specific to the operation. If additional items exist beyond the
-- maximum you specify, the @NextToken@ response element is present and has
-- a value (is not null). Include that value as the @NextToken@ request
-- parameter in the next call to the operation to get the next part of the
-- results. Note that Organizations might return fewer results than the
-- maximum even when there are more results available. You should check
-- @NextToken@ after every operation to ensure that you receive all of the
-- results.
listPoliciesForTarget_maxResults :: Lens.Lens' ListPoliciesForTarget (Prelude.Maybe Prelude.Natural)
listPoliciesForTarget_maxResults :: Lens' ListPoliciesForTarget (Maybe Natural)
listPoliciesForTarget_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTarget' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListPoliciesForTarget
s@ListPoliciesForTarget' {} Maybe Natural
a -> ListPoliciesForTarget
s {$sel:maxResults:ListPoliciesForTarget' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListPoliciesForTarget)

-- | The parameter for receiving additional results if you receive a
-- @NextToken@ response in a previous request. A @NextToken@ response
-- indicates that more output is available. Set this parameter to the value
-- of the previous call\'s @NextToken@ response to indicate where the
-- output should continue from.
listPoliciesForTarget_nextToken :: Lens.Lens' ListPoliciesForTarget (Prelude.Maybe Prelude.Text)
listPoliciesForTarget_nextToken :: Lens' ListPoliciesForTarget (Maybe Text)
listPoliciesForTarget_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTarget' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListPoliciesForTarget
s@ListPoliciesForTarget' {} Maybe Text
a -> ListPoliciesForTarget
s {$sel:nextToken:ListPoliciesForTarget' :: Maybe Text
nextToken = Maybe Text
a} :: ListPoliciesForTarget)

-- | The unique identifier (ID) of the root, organizational unit, or account
-- whose policies you want to list.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a target ID
-- string requires one of the following:
--
-- -   __Root__ - A string that begins with \"r-\" followed by from 4 to 32
--     lowercase letters or digits.
--
-- -   __Account__ - A string that consists of exactly 12 digits.
--
-- -   __Organizational unit (OU)__ - A string that begins with \"ou-\"
--     followed by from 4 to 32 lowercase letters or digits (the ID of the
--     root that the OU is in). This string is followed by a second \"-\"
--     dash and from 8 to 32 additional lowercase letters or digits.
listPoliciesForTarget_targetId :: Lens.Lens' ListPoliciesForTarget Prelude.Text
listPoliciesForTarget_targetId :: Lens' ListPoliciesForTarget Text
listPoliciesForTarget_targetId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTarget' {Text
targetId :: Text
$sel:targetId:ListPoliciesForTarget' :: ListPoliciesForTarget -> Text
targetId} -> Text
targetId) (\s :: ListPoliciesForTarget
s@ListPoliciesForTarget' {} Text
a -> ListPoliciesForTarget
s {$sel:targetId:ListPoliciesForTarget' :: Text
targetId = Text
a} :: ListPoliciesForTarget)

-- | The type of policy that you want to include in the returned list. You
-- must specify one of the following values:
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
listPoliciesForTarget_filter :: Lens.Lens' ListPoliciesForTarget PolicyType
listPoliciesForTarget_filter :: Lens' ListPoliciesForTarget PolicyType
listPoliciesForTarget_filter = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTarget' {PolicyType
filter' :: PolicyType
$sel:filter':ListPoliciesForTarget' :: ListPoliciesForTarget -> PolicyType
filter'} -> PolicyType
filter') (\s :: ListPoliciesForTarget
s@ListPoliciesForTarget' {} PolicyType
a -> ListPoliciesForTarget
s {$sel:filter':ListPoliciesForTarget' :: PolicyType
filter' = PolicyType
a} :: ListPoliciesForTarget)

instance Core.AWSPager ListPoliciesForTarget where
  page :: ListPoliciesForTarget
-> AWSResponse ListPoliciesForTarget -> Maybe ListPoliciesForTarget
page ListPoliciesForTarget
rq AWSResponse ListPoliciesForTarget
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListPoliciesForTarget
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListPoliciesForTargetResponse (Maybe Text)
listPoliciesForTargetResponse_nextToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListPoliciesForTarget
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListPoliciesForTargetResponse (Maybe [PolicySummary])
listPoliciesForTargetResponse_policies
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ ListPoliciesForTarget
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListPoliciesForTarget (Maybe Text)
listPoliciesForTarget_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListPoliciesForTarget
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListPoliciesForTargetResponse (Maybe Text)
listPoliciesForTargetResponse_nextToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListPoliciesForTarget where
  type
    AWSResponse ListPoliciesForTarget =
      ListPoliciesForTargetResponse
  request :: (Service -> Service)
-> ListPoliciesForTarget -> Request ListPoliciesForTarget
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 ListPoliciesForTarget
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListPoliciesForTarget)))
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 [PolicySummary] -> Int -> ListPoliciesForTargetResponse
ListPoliciesForTargetResponse'
            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
"NextToken")
            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
"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 ListPoliciesForTarget where
  hashWithSalt :: Int -> ListPoliciesForTarget -> Int
hashWithSalt Int
_salt ListPoliciesForTarget' {Maybe Natural
Maybe Text
Text
PolicyType
filter' :: PolicyType
targetId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:filter':ListPoliciesForTarget' :: ListPoliciesForTarget -> PolicyType
$sel:targetId:ListPoliciesForTarget' :: ListPoliciesForTarget -> Text
$sel:nextToken:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Text
$sel:maxResults:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
targetId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PolicyType
filter'

instance Prelude.NFData ListPoliciesForTarget where
  rnf :: ListPoliciesForTarget -> ()
rnf ListPoliciesForTarget' {Maybe Natural
Maybe Text
Text
PolicyType
filter' :: PolicyType
targetId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:filter':ListPoliciesForTarget' :: ListPoliciesForTarget -> PolicyType
$sel:targetId:ListPoliciesForTarget' :: ListPoliciesForTarget -> Text
$sel:nextToken:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Text
$sel:maxResults:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
targetId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PolicyType
filter'

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

instance Data.ToJSON ListPoliciesForTarget where
  toJSON :: ListPoliciesForTarget -> Value
toJSON ListPoliciesForTarget' {Maybe Natural
Maybe Text
Text
PolicyType
filter' :: PolicyType
targetId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:filter':ListPoliciesForTarget' :: ListPoliciesForTarget -> PolicyType
$sel:targetId:ListPoliciesForTarget' :: ListPoliciesForTarget -> Text
$sel:nextToken:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Text
$sel:maxResults:ListPoliciesForTarget' :: ListPoliciesForTarget -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxResults" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            (Key
"NextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            forall a. a -> Maybe a
Prelude.Just (Key
"TargetId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
targetId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Filter" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= PolicyType
filter')
          ]
      )

instance Data.ToPath ListPoliciesForTarget where
  toPath :: ListPoliciesForTarget -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListPoliciesForTargetResponse' smart constructor.
data ListPoliciesForTargetResponse = ListPoliciesForTargetResponse'
  { -- | If present, indicates that more output is available than is included in
    -- the current response. Use this value in the @NextToken@ request
    -- parameter in a subsequent call to the operation to get the next part of
    -- the output. You should repeat this until the @NextToken@ response
    -- element comes back as @null@.
    ListPoliciesForTargetResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The list of policies that match the criteria in the request.
    ListPoliciesForTargetResponse -> Maybe [PolicySummary]
policies :: Prelude.Maybe [PolicySummary],
    -- | The response's http status code.
    ListPoliciesForTargetResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
$c/= :: ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
== :: ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
$c== :: ListPoliciesForTargetResponse
-> ListPoliciesForTargetResponse -> Bool
Prelude.Eq, ReadPrec [ListPoliciesForTargetResponse]
ReadPrec ListPoliciesForTargetResponse
Int -> ReadS ListPoliciesForTargetResponse
ReadS [ListPoliciesForTargetResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPoliciesForTargetResponse]
$creadListPrec :: ReadPrec [ListPoliciesForTargetResponse]
readPrec :: ReadPrec ListPoliciesForTargetResponse
$creadPrec :: ReadPrec ListPoliciesForTargetResponse
readList :: ReadS [ListPoliciesForTargetResponse]
$creadList :: ReadS [ListPoliciesForTargetResponse]
readsPrec :: Int -> ReadS ListPoliciesForTargetResponse
$creadsPrec :: Int -> ReadS ListPoliciesForTargetResponse
Prelude.Read, Int -> ListPoliciesForTargetResponse -> ShowS
[ListPoliciesForTargetResponse] -> ShowS
ListPoliciesForTargetResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPoliciesForTargetResponse] -> ShowS
$cshowList :: [ListPoliciesForTargetResponse] -> ShowS
show :: ListPoliciesForTargetResponse -> String
$cshow :: ListPoliciesForTargetResponse -> String
showsPrec :: Int -> ListPoliciesForTargetResponse -> ShowS
$cshowsPrec :: Int -> ListPoliciesForTargetResponse -> ShowS
Prelude.Show, forall x.
Rep ListPoliciesForTargetResponse x
-> ListPoliciesForTargetResponse
forall x.
ListPoliciesForTargetResponse
-> Rep ListPoliciesForTargetResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListPoliciesForTargetResponse x
-> ListPoliciesForTargetResponse
$cfrom :: forall x.
ListPoliciesForTargetResponse
-> Rep ListPoliciesForTargetResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListPoliciesForTargetResponse' 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:
--
-- 'nextToken', 'listPoliciesForTargetResponse_nextToken' - If present, indicates that more output is available than is included in
-- the current response. Use this value in the @NextToken@ request
-- parameter in a subsequent call to the operation to get the next part of
-- the output. You should repeat this until the @NextToken@ response
-- element comes back as @null@.
--
-- 'policies', 'listPoliciesForTargetResponse_policies' - The list of policies that match the criteria in the request.
--
-- 'httpStatus', 'listPoliciesForTargetResponse_httpStatus' - The response's http status code.
newListPoliciesForTargetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListPoliciesForTargetResponse
newListPoliciesForTargetResponse :: Int -> ListPoliciesForTargetResponse
newListPoliciesForTargetResponse Int
pHttpStatus_ =
  ListPoliciesForTargetResponse'
    { $sel:nextToken:ListPoliciesForTargetResponse' :: Maybe Text
nextToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:policies:ListPoliciesForTargetResponse' :: Maybe [PolicySummary]
policies = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListPoliciesForTargetResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If present, indicates that more output is available than is included in
-- the current response. Use this value in the @NextToken@ request
-- parameter in a subsequent call to the operation to get the next part of
-- the output. You should repeat this until the @NextToken@ response
-- element comes back as @null@.
listPoliciesForTargetResponse_nextToken :: Lens.Lens' ListPoliciesForTargetResponse (Prelude.Maybe Prelude.Text)
listPoliciesForTargetResponse_nextToken :: Lens' ListPoliciesForTargetResponse (Maybe Text)
listPoliciesForTargetResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTargetResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListPoliciesForTargetResponse' :: ListPoliciesForTargetResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListPoliciesForTargetResponse
s@ListPoliciesForTargetResponse' {} Maybe Text
a -> ListPoliciesForTargetResponse
s {$sel:nextToken:ListPoliciesForTargetResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListPoliciesForTargetResponse)

-- | The list of policies that match the criteria in the request.
listPoliciesForTargetResponse_policies :: Lens.Lens' ListPoliciesForTargetResponse (Prelude.Maybe [PolicySummary])
listPoliciesForTargetResponse_policies :: Lens' ListPoliciesForTargetResponse (Maybe [PolicySummary])
listPoliciesForTargetResponse_policies = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTargetResponse' {Maybe [PolicySummary]
policies :: Maybe [PolicySummary]
$sel:policies:ListPoliciesForTargetResponse' :: ListPoliciesForTargetResponse -> Maybe [PolicySummary]
policies} -> Maybe [PolicySummary]
policies) (\s :: ListPoliciesForTargetResponse
s@ListPoliciesForTargetResponse' {} Maybe [PolicySummary]
a -> ListPoliciesForTargetResponse
s {$sel:policies:ListPoliciesForTargetResponse' :: Maybe [PolicySummary]
policies = Maybe [PolicySummary]
a} :: ListPoliciesForTargetResponse) 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.
listPoliciesForTargetResponse_httpStatus :: Lens.Lens' ListPoliciesForTargetResponse Prelude.Int
listPoliciesForTargetResponse_httpStatus :: Lens' ListPoliciesForTargetResponse Int
listPoliciesForTargetResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPoliciesForTargetResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListPoliciesForTargetResponse' :: ListPoliciesForTargetResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListPoliciesForTargetResponse
s@ListPoliciesForTargetResponse' {} Int
a -> ListPoliciesForTargetResponse
s {$sel:httpStatus:ListPoliciesForTargetResponse' :: Int
httpStatus = Int
a} :: ListPoliciesForTargetResponse)

instance Prelude.NFData ListPoliciesForTargetResponse where
  rnf :: ListPoliciesForTargetResponse -> ()
rnf ListPoliciesForTargetResponse' {Int
Maybe [PolicySummary]
Maybe Text
httpStatus :: Int
policies :: Maybe [PolicySummary]
nextToken :: Maybe Text
$sel:httpStatus:ListPoliciesForTargetResponse' :: ListPoliciesForTargetResponse -> Int
$sel:policies:ListPoliciesForTargetResponse' :: ListPoliciesForTargetResponse -> Maybe [PolicySummary]
$sel:nextToken:ListPoliciesForTargetResponse' :: ListPoliciesForTargetResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [PolicySummary]
policies
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus