{-# 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.ListTargetsForPolicy
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists all the roots, organizational units (OUs), and accounts that the
-- specified policy is attached to.
--
-- 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
-- AWS service.
--
-- This operation returns paginated results.
module Amazonka.Organizations.ListTargetsForPolicy
  ( -- * Creating a Request
    ListTargetsForPolicy (..),
    newListTargetsForPolicy,

    -- * Request Lenses
    listTargetsForPolicy_nextToken,
    listTargetsForPolicy_maxResults,
    listTargetsForPolicy_policyId,

    -- * Destructuring the Response
    ListTargetsForPolicyResponse (..),
    newListTargetsForPolicyResponse,

    -- * Response Lenses
    listTargetsForPolicyResponse_nextToken,
    listTargetsForPolicyResponse_targets,
    listTargetsForPolicyResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListTargetsForPolicy' smart constructor.
data ListTargetsForPolicy = ListTargetsForPolicy'
  { -- | 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.
    ListTargetsForPolicy -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | 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.
    ListTargetsForPolicy -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The unique identifier (ID) of the policy whose attachments you want to
    -- know.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for a policy ID
    -- string requires \"p-\" followed by from 8 to 128 lowercase or uppercase
    -- letters, digits, or the underscore character (_).
    ListTargetsForPolicy -> Text
policyId :: Prelude.Text
  }
  deriving (ListTargetsForPolicy -> ListTargetsForPolicy -> Bool
(ListTargetsForPolicy -> ListTargetsForPolicy -> Bool)
-> (ListTargetsForPolicy -> ListTargetsForPolicy -> Bool)
-> Eq ListTargetsForPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTargetsForPolicy -> ListTargetsForPolicy -> Bool
$c/= :: ListTargetsForPolicy -> ListTargetsForPolicy -> Bool
== :: ListTargetsForPolicy -> ListTargetsForPolicy -> Bool
$c== :: ListTargetsForPolicy -> ListTargetsForPolicy -> Bool
Prelude.Eq, ReadPrec [ListTargetsForPolicy]
ReadPrec ListTargetsForPolicy
Int -> ReadS ListTargetsForPolicy
ReadS [ListTargetsForPolicy]
(Int -> ReadS ListTargetsForPolicy)
-> ReadS [ListTargetsForPolicy]
-> ReadPrec ListTargetsForPolicy
-> ReadPrec [ListTargetsForPolicy]
-> Read ListTargetsForPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTargetsForPolicy]
$creadListPrec :: ReadPrec [ListTargetsForPolicy]
readPrec :: ReadPrec ListTargetsForPolicy
$creadPrec :: ReadPrec ListTargetsForPolicy
readList :: ReadS [ListTargetsForPolicy]
$creadList :: ReadS [ListTargetsForPolicy]
readsPrec :: Int -> ReadS ListTargetsForPolicy
$creadsPrec :: Int -> ReadS ListTargetsForPolicy
Prelude.Read, Int -> ListTargetsForPolicy -> ShowS
[ListTargetsForPolicy] -> ShowS
ListTargetsForPolicy -> String
(Int -> ListTargetsForPolicy -> ShowS)
-> (ListTargetsForPolicy -> String)
-> ([ListTargetsForPolicy] -> ShowS)
-> Show ListTargetsForPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTargetsForPolicy] -> ShowS
$cshowList :: [ListTargetsForPolicy] -> ShowS
show :: ListTargetsForPolicy -> String
$cshow :: ListTargetsForPolicy -> String
showsPrec :: Int -> ListTargetsForPolicy -> ShowS
$cshowsPrec :: Int -> ListTargetsForPolicy -> ShowS
Prelude.Show, (forall x. ListTargetsForPolicy -> Rep ListTargetsForPolicy x)
-> (forall x. Rep ListTargetsForPolicy x -> ListTargetsForPolicy)
-> Generic ListTargetsForPolicy
forall x. Rep ListTargetsForPolicy x -> ListTargetsForPolicy
forall x. ListTargetsForPolicy -> Rep ListTargetsForPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTargetsForPolicy x -> ListTargetsForPolicy
$cfrom :: forall x. ListTargetsForPolicy -> Rep ListTargetsForPolicy x
Prelude.Generic)

-- |
-- Create a value of 'ListTargetsForPolicy' 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', 'listTargetsForPolicy_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.
--
-- 'maxResults', 'listTargetsForPolicy_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.
--
-- 'policyId', 'listTargetsForPolicy_policyId' - The unique identifier (ID) of the policy whose attachments you want to
-- know.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a policy ID
-- string requires \"p-\" followed by from 8 to 128 lowercase or uppercase
-- letters, digits, or the underscore character (_).
newListTargetsForPolicy ::
  -- | 'policyId'
  Prelude.Text ->
  ListTargetsForPolicy
newListTargetsForPolicy :: Text -> ListTargetsForPolicy
newListTargetsForPolicy Text
pPolicyId_ =
  ListTargetsForPolicy' :: Maybe Text -> Maybe Natural -> Text -> ListTargetsForPolicy
ListTargetsForPolicy'
    { $sel:nextToken:ListTargetsForPolicy' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListTargetsForPolicy' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:policyId:ListTargetsForPolicy' :: Text
policyId = Text
pPolicyId_
    }

-- | 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.
listTargetsForPolicy_nextToken :: Lens.Lens' ListTargetsForPolicy (Prelude.Maybe Prelude.Text)
listTargetsForPolicy_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListTargetsForPolicy -> f ListTargetsForPolicy
listTargetsForPolicy_nextToken = (ListTargetsForPolicy -> Maybe Text)
-> (ListTargetsForPolicy -> Maybe Text -> ListTargetsForPolicy)
-> Lens
     ListTargetsForPolicy ListTargetsForPolicy (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTargetsForPolicy' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTargetsForPolicy' :: ListTargetsForPolicy -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTargetsForPolicy
s@ListTargetsForPolicy' {} Maybe Text
a -> ListTargetsForPolicy
s {$sel:nextToken:ListTargetsForPolicy' :: Maybe Text
nextToken = Maybe Text
a} :: ListTargetsForPolicy)

-- | 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.
listTargetsForPolicy_maxResults :: Lens.Lens' ListTargetsForPolicy (Prelude.Maybe Prelude.Natural)
listTargetsForPolicy_maxResults :: (Maybe Natural -> f (Maybe Natural))
-> ListTargetsForPolicy -> f ListTargetsForPolicy
listTargetsForPolicy_maxResults = (ListTargetsForPolicy -> Maybe Natural)
-> (ListTargetsForPolicy -> Maybe Natural -> ListTargetsForPolicy)
-> Lens
     ListTargetsForPolicy
     ListTargetsForPolicy
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTargetsForPolicy' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListTargetsForPolicy' :: ListTargetsForPolicy -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListTargetsForPolicy
s@ListTargetsForPolicy' {} Maybe Natural
a -> ListTargetsForPolicy
s {$sel:maxResults:ListTargetsForPolicy' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListTargetsForPolicy)

-- | The unique identifier (ID) of the policy whose attachments you want to
-- know.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a policy ID
-- string requires \"p-\" followed by from 8 to 128 lowercase or uppercase
-- letters, digits, or the underscore character (_).
listTargetsForPolicy_policyId :: Lens.Lens' ListTargetsForPolicy Prelude.Text
listTargetsForPolicy_policyId :: (Text -> f Text) -> ListTargetsForPolicy -> f ListTargetsForPolicy
listTargetsForPolicy_policyId = (ListTargetsForPolicy -> Text)
-> (ListTargetsForPolicy -> Text -> ListTargetsForPolicy)
-> Lens ListTargetsForPolicy ListTargetsForPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTargetsForPolicy' {Text
policyId :: Text
$sel:policyId:ListTargetsForPolicy' :: ListTargetsForPolicy -> Text
policyId} -> Text
policyId) (\s :: ListTargetsForPolicy
s@ListTargetsForPolicy' {} Text
a -> ListTargetsForPolicy
s {$sel:policyId:ListTargetsForPolicy' :: Text
policyId = Text
a} :: ListTargetsForPolicy)

instance Core.AWSPager ListTargetsForPolicy where
  page :: ListTargetsForPolicy
-> AWSResponse ListTargetsForPolicy -> Maybe ListTargetsForPolicy
page ListTargetsForPolicy
rq AWSResponse ListTargetsForPolicy
rs
    | Maybe Text -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListTargetsForPolicy
ListTargetsForPolicyResponse
rs
            ListTargetsForPolicyResponse
-> Getting (First Text) ListTargetsForPolicyResponse Text
-> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> ListTargetsForPolicyResponse
-> Const (First Text) ListTargetsForPolicyResponse
Lens' ListTargetsForPolicyResponse (Maybe Text)
listTargetsForPolicyResponse_nextToken
              ((Maybe Text -> Const (First Text) (Maybe Text))
 -> ListTargetsForPolicyResponse
 -> Const (First Text) ListTargetsForPolicyResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) ListTargetsForPolicyResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe ListTargetsForPolicy
forall a. Maybe a
Prelude.Nothing
    | Maybe [PolicyTargetSummary] -> Bool
forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListTargetsForPolicy
ListTargetsForPolicyResponse
rs
            ListTargetsForPolicyResponse
-> Getting
     (First [PolicyTargetSummary])
     ListTargetsForPolicyResponse
     [PolicyTargetSummary]
-> Maybe [PolicyTargetSummary]
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe [PolicyTargetSummary]
 -> Const
      (First [PolicyTargetSummary]) (Maybe [PolicyTargetSummary]))
-> ListTargetsForPolicyResponse
-> Const (First [PolicyTargetSummary]) ListTargetsForPolicyResponse
Lens' ListTargetsForPolicyResponse (Maybe [PolicyTargetSummary])
listTargetsForPolicyResponse_targets
              ((Maybe [PolicyTargetSummary]
  -> Const
       (First [PolicyTargetSummary]) (Maybe [PolicyTargetSummary]))
 -> ListTargetsForPolicyResponse
 -> Const
      (First [PolicyTargetSummary]) ListTargetsForPolicyResponse)
-> (([PolicyTargetSummary]
     -> Const (First [PolicyTargetSummary]) [PolicyTargetSummary])
    -> Maybe [PolicyTargetSummary]
    -> Const
         (First [PolicyTargetSummary]) (Maybe [PolicyTargetSummary]))
-> Getting
     (First [PolicyTargetSummary])
     ListTargetsForPolicyResponse
     [PolicyTargetSummary]
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([PolicyTargetSummary]
 -> Const (First [PolicyTargetSummary]) [PolicyTargetSummary])
-> Maybe [PolicyTargetSummary]
-> Const
     (First [PolicyTargetSummary]) (Maybe [PolicyTargetSummary])
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
      Maybe ListTargetsForPolicy
forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
      ListTargetsForPolicy -> Maybe ListTargetsForPolicy
forall a. a -> Maybe a
Prelude.Just (ListTargetsForPolicy -> Maybe ListTargetsForPolicy)
-> ListTargetsForPolicy -> Maybe ListTargetsForPolicy
forall a b. (a -> b) -> a -> b
Prelude.$
        ListTargetsForPolicy
rq
          ListTargetsForPolicy
-> (ListTargetsForPolicy -> ListTargetsForPolicy)
-> ListTargetsForPolicy
forall a b. a -> (a -> b) -> b
Prelude.& (Maybe Text -> Identity (Maybe Text))
-> ListTargetsForPolicy -> Identity ListTargetsForPolicy
Lens
  ListTargetsForPolicy ListTargetsForPolicy (Maybe Text) (Maybe Text)
listTargetsForPolicy_nextToken
          ((Maybe Text -> Identity (Maybe Text))
 -> ListTargetsForPolicy -> Identity ListTargetsForPolicy)
-> Maybe Text -> ListTargetsForPolicy -> ListTargetsForPolicy
forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListTargetsForPolicy
ListTargetsForPolicyResponse
rs
          ListTargetsForPolicyResponse
-> Getting (First Text) ListTargetsForPolicyResponse Text
-> Maybe Text
forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? (Maybe Text -> Const (First Text) (Maybe Text))
-> ListTargetsForPolicyResponse
-> Const (First Text) ListTargetsForPolicyResponse
Lens' ListTargetsForPolicyResponse (Maybe Text)
listTargetsForPolicyResponse_nextToken
            ((Maybe Text -> Const (First Text) (Maybe Text))
 -> ListTargetsForPolicyResponse
 -> Const (First Text) ListTargetsForPolicyResponse)
-> ((Text -> Const (First Text) Text)
    -> Maybe Text -> Const (First Text) (Maybe Text))
-> Getting (First Text) ListTargetsForPolicyResponse Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> Const (First Text) Text)
-> Maybe Text -> Const (First Text) (Maybe Text)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest ListTargetsForPolicy where
  type
    AWSResponse ListTargetsForPolicy =
      ListTargetsForPolicyResponse
  request :: ListTargetsForPolicy -> Request ListTargetsForPolicy
request = Service -> ListTargetsForPolicy -> Request ListTargetsForPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ListTargetsForPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListTargetsForPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ListTargetsForPolicy))
-> Logger
-> Service
-> Proxy ListTargetsForPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListTargetsForPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe [PolicyTargetSummary]
-> Int
-> ListTargetsForPolicyResponse
ListTargetsForPolicyResponse'
            (Maybe Text
 -> Maybe [PolicyTargetSummary]
 -> Int
 -> ListTargetsForPolicyResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe [PolicyTargetSummary]
      -> Int -> ListTargetsForPolicyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"NextToken")
            Either
  String
  (Maybe [PolicyTargetSummary]
   -> Int -> ListTargetsForPolicyResponse)
-> Either String (Maybe [PolicyTargetSummary])
-> Either String (Int -> ListTargetsForPolicyResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Either String (Maybe (Maybe [PolicyTargetSummary]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Targets" Either String (Maybe (Maybe [PolicyTargetSummary]))
-> Maybe [PolicyTargetSummary]
-> Either String (Maybe [PolicyTargetSummary])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [PolicyTargetSummary]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> ListTargetsForPolicyResponse)
-> Either String Int -> Either String ListTargetsForPolicyResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListTargetsForPolicy

instance Prelude.NFData ListTargetsForPolicy

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

instance Core.ToJSON ListTargetsForPolicy where
  toJSON :: ListTargetsForPolicy -> Value
toJSON ListTargetsForPolicy' {Maybe Natural
Maybe Text
Text
policyId :: Text
maxResults :: Maybe Natural
nextToken :: Maybe Text
$sel:policyId:ListTargetsForPolicy' :: ListTargetsForPolicy -> Text
$sel:maxResults:ListTargetsForPolicy' :: ListTargetsForPolicy -> Maybe Natural
$sel:nextToken:ListTargetsForPolicy' :: ListTargetsForPolicy -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NextToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            (Text
"MaxResults" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PolicyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policyId)
          ]
      )

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

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

-- | /See:/ 'newListTargetsForPolicyResponse' smart constructor.
data ListTargetsForPolicyResponse = ListTargetsForPolicyResponse'
  { -- | 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@.
    ListTargetsForPolicyResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A list of structures, each of which contains details about one of the
    -- entities to which the specified policy is attached.
    ListTargetsForPolicyResponse -> Maybe [PolicyTargetSummary]
targets :: Prelude.Maybe [PolicyTargetSummary],
    -- | The response's http status code.
    ListTargetsForPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListTargetsForPolicyResponse
-> ListTargetsForPolicyResponse -> Bool
(ListTargetsForPolicyResponse
 -> ListTargetsForPolicyResponse -> Bool)
-> (ListTargetsForPolicyResponse
    -> ListTargetsForPolicyResponse -> Bool)
-> Eq ListTargetsForPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTargetsForPolicyResponse
-> ListTargetsForPolicyResponse -> Bool
$c/= :: ListTargetsForPolicyResponse
-> ListTargetsForPolicyResponse -> Bool
== :: ListTargetsForPolicyResponse
-> ListTargetsForPolicyResponse -> Bool
$c== :: ListTargetsForPolicyResponse
-> ListTargetsForPolicyResponse -> Bool
Prelude.Eq, ReadPrec [ListTargetsForPolicyResponse]
ReadPrec ListTargetsForPolicyResponse
Int -> ReadS ListTargetsForPolicyResponse
ReadS [ListTargetsForPolicyResponse]
(Int -> ReadS ListTargetsForPolicyResponse)
-> ReadS [ListTargetsForPolicyResponse]
-> ReadPrec ListTargetsForPolicyResponse
-> ReadPrec [ListTargetsForPolicyResponse]
-> Read ListTargetsForPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTargetsForPolicyResponse]
$creadListPrec :: ReadPrec [ListTargetsForPolicyResponse]
readPrec :: ReadPrec ListTargetsForPolicyResponse
$creadPrec :: ReadPrec ListTargetsForPolicyResponse
readList :: ReadS [ListTargetsForPolicyResponse]
$creadList :: ReadS [ListTargetsForPolicyResponse]
readsPrec :: Int -> ReadS ListTargetsForPolicyResponse
$creadsPrec :: Int -> ReadS ListTargetsForPolicyResponse
Prelude.Read, Int -> ListTargetsForPolicyResponse -> ShowS
[ListTargetsForPolicyResponse] -> ShowS
ListTargetsForPolicyResponse -> String
(Int -> ListTargetsForPolicyResponse -> ShowS)
-> (ListTargetsForPolicyResponse -> String)
-> ([ListTargetsForPolicyResponse] -> ShowS)
-> Show ListTargetsForPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTargetsForPolicyResponse] -> ShowS
$cshowList :: [ListTargetsForPolicyResponse] -> ShowS
show :: ListTargetsForPolicyResponse -> String
$cshow :: ListTargetsForPolicyResponse -> String
showsPrec :: Int -> ListTargetsForPolicyResponse -> ShowS
$cshowsPrec :: Int -> ListTargetsForPolicyResponse -> ShowS
Prelude.Show, (forall x.
 ListTargetsForPolicyResponse -> Rep ListTargetsForPolicyResponse x)
-> (forall x.
    Rep ListTargetsForPolicyResponse x -> ListTargetsForPolicyResponse)
-> Generic ListTargetsForPolicyResponse
forall x.
Rep ListTargetsForPolicyResponse x -> ListTargetsForPolicyResponse
forall x.
ListTargetsForPolicyResponse -> Rep ListTargetsForPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListTargetsForPolicyResponse x -> ListTargetsForPolicyResponse
$cfrom :: forall x.
ListTargetsForPolicyResponse -> Rep ListTargetsForPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListTargetsForPolicyResponse' 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', 'listTargetsForPolicyResponse_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@.
--
-- 'targets', 'listTargetsForPolicyResponse_targets' - A list of structures, each of which contains details about one of the
-- entities to which the specified policy is attached.
--
-- 'httpStatus', 'listTargetsForPolicyResponse_httpStatus' - The response's http status code.
newListTargetsForPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListTargetsForPolicyResponse
newListTargetsForPolicyResponse :: Int -> ListTargetsForPolicyResponse
newListTargetsForPolicyResponse Int
pHttpStatus_ =
  ListTargetsForPolicyResponse' :: Maybe Text
-> Maybe [PolicyTargetSummary]
-> Int
-> ListTargetsForPolicyResponse
ListTargetsForPolicyResponse'
    { $sel:nextToken:ListTargetsForPolicyResponse' :: Maybe Text
nextToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:targets:ListTargetsForPolicyResponse' :: Maybe [PolicyTargetSummary]
targets = Maybe [PolicyTargetSummary]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListTargetsForPolicyResponse' :: 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@.
listTargetsForPolicyResponse_nextToken :: Lens.Lens' ListTargetsForPolicyResponse (Prelude.Maybe Prelude.Text)
listTargetsForPolicyResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListTargetsForPolicyResponse -> f ListTargetsForPolicyResponse
listTargetsForPolicyResponse_nextToken = (ListTargetsForPolicyResponse -> Maybe Text)
-> (ListTargetsForPolicyResponse
    -> Maybe Text -> ListTargetsForPolicyResponse)
-> Lens' ListTargetsForPolicyResponse (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTargetsForPolicyResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTargetsForPolicyResponse' :: ListTargetsForPolicyResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTargetsForPolicyResponse
s@ListTargetsForPolicyResponse' {} Maybe Text
a -> ListTargetsForPolicyResponse
s {$sel:nextToken:ListTargetsForPolicyResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListTargetsForPolicyResponse)

-- | A list of structures, each of which contains details about one of the
-- entities to which the specified policy is attached.
listTargetsForPolicyResponse_targets :: Lens.Lens' ListTargetsForPolicyResponse (Prelude.Maybe [PolicyTargetSummary])
listTargetsForPolicyResponse_targets :: (Maybe [PolicyTargetSummary] -> f (Maybe [PolicyTargetSummary]))
-> ListTargetsForPolicyResponse -> f ListTargetsForPolicyResponse
listTargetsForPolicyResponse_targets = (ListTargetsForPolicyResponse -> Maybe [PolicyTargetSummary])
-> (ListTargetsForPolicyResponse
    -> Maybe [PolicyTargetSummary] -> ListTargetsForPolicyResponse)
-> Lens' ListTargetsForPolicyResponse (Maybe [PolicyTargetSummary])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTargetsForPolicyResponse' {Maybe [PolicyTargetSummary]
targets :: Maybe [PolicyTargetSummary]
$sel:targets:ListTargetsForPolicyResponse' :: ListTargetsForPolicyResponse -> Maybe [PolicyTargetSummary]
targets} -> Maybe [PolicyTargetSummary]
targets) (\s :: ListTargetsForPolicyResponse
s@ListTargetsForPolicyResponse' {} Maybe [PolicyTargetSummary]
a -> ListTargetsForPolicyResponse
s {$sel:targets:ListTargetsForPolicyResponse' :: Maybe [PolicyTargetSummary]
targets = Maybe [PolicyTargetSummary]
a} :: ListTargetsForPolicyResponse) ((Maybe [PolicyTargetSummary] -> f (Maybe [PolicyTargetSummary]))
 -> ListTargetsForPolicyResponse -> f ListTargetsForPolicyResponse)
-> ((Maybe [PolicyTargetSummary]
     -> f (Maybe [PolicyTargetSummary]))
    -> Maybe [PolicyTargetSummary] -> f (Maybe [PolicyTargetSummary]))
-> (Maybe [PolicyTargetSummary] -> f (Maybe [PolicyTargetSummary]))
-> ListTargetsForPolicyResponse
-> f ListTargetsForPolicyResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PolicyTargetSummary]
  [PolicyTargetSummary]
  [PolicyTargetSummary]
  [PolicyTargetSummary]
-> Iso
     (Maybe [PolicyTargetSummary])
     (Maybe [PolicyTargetSummary])
     (Maybe [PolicyTargetSummary])
     (Maybe [PolicyTargetSummary])
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 AnIso
  [PolicyTargetSummary]
  [PolicyTargetSummary]
  [PolicyTargetSummary]
  [PolicyTargetSummary]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ListTargetsForPolicyResponse