{-# 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.AuditManager.GetDelegations
-- 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)
--
-- Returns a list of delegations from an audit owner to a delegate.
module Amazonka.AuditManager.GetDelegations
  ( -- * Creating a Request
    GetDelegations (..),
    newGetDelegations,

    -- * Request Lenses
    getDelegations_nextToken,
    getDelegations_maxResults,

    -- * Destructuring the Response
    GetDelegationsResponse (..),
    newGetDelegationsResponse,

    -- * Response Lenses
    getDelegationsResponse_delegations,
    getDelegationsResponse_nextToken,
    getDelegationsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetDelegations' smart constructor.
data GetDelegations = GetDelegations'
  { -- | The pagination token used to fetch the next set of results.
    GetDelegations -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Represents the maximum number of results per page, or per API request
    -- call.
    GetDelegations -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural
  }
  deriving (GetDelegations -> GetDelegations -> Bool
(GetDelegations -> GetDelegations -> Bool)
-> (GetDelegations -> GetDelegations -> Bool) -> Eq GetDelegations
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDelegations -> GetDelegations -> Bool
$c/= :: GetDelegations -> GetDelegations -> Bool
== :: GetDelegations -> GetDelegations -> Bool
$c== :: GetDelegations -> GetDelegations -> Bool
Prelude.Eq, ReadPrec [GetDelegations]
ReadPrec GetDelegations
Int -> ReadS GetDelegations
ReadS [GetDelegations]
(Int -> ReadS GetDelegations)
-> ReadS [GetDelegations]
-> ReadPrec GetDelegations
-> ReadPrec [GetDelegations]
-> Read GetDelegations
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDelegations]
$creadListPrec :: ReadPrec [GetDelegations]
readPrec :: ReadPrec GetDelegations
$creadPrec :: ReadPrec GetDelegations
readList :: ReadS [GetDelegations]
$creadList :: ReadS [GetDelegations]
readsPrec :: Int -> ReadS GetDelegations
$creadsPrec :: Int -> ReadS GetDelegations
Prelude.Read, Int -> GetDelegations -> ShowS
[GetDelegations] -> ShowS
GetDelegations -> String
(Int -> GetDelegations -> ShowS)
-> (GetDelegations -> String)
-> ([GetDelegations] -> ShowS)
-> Show GetDelegations
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDelegations] -> ShowS
$cshowList :: [GetDelegations] -> ShowS
show :: GetDelegations -> String
$cshow :: GetDelegations -> String
showsPrec :: Int -> GetDelegations -> ShowS
$cshowsPrec :: Int -> GetDelegations -> ShowS
Prelude.Show, (forall x. GetDelegations -> Rep GetDelegations x)
-> (forall x. Rep GetDelegations x -> GetDelegations)
-> Generic GetDelegations
forall x. Rep GetDelegations x -> GetDelegations
forall x. GetDelegations -> Rep GetDelegations x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDelegations x -> GetDelegations
$cfrom :: forall x. GetDelegations -> Rep GetDelegations x
Prelude.Generic)

-- |
-- Create a value of 'GetDelegations' 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', 'getDelegations_nextToken' - The pagination token used to fetch the next set of results.
--
-- 'maxResults', 'getDelegations_maxResults' - Represents the maximum number of results per page, or per API request
-- call.
newGetDelegations ::
  GetDelegations
newGetDelegations :: GetDelegations
newGetDelegations =
  GetDelegations' :: Maybe Text -> Maybe Natural -> GetDelegations
GetDelegations'
    { $sel:nextToken:GetDelegations' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:GetDelegations' :: Maybe Natural
maxResults = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The pagination token used to fetch the next set of results.
getDelegations_nextToken :: Lens.Lens' GetDelegations (Prelude.Maybe Prelude.Text)
getDelegations_nextToken :: (Maybe Text -> f (Maybe Text))
-> GetDelegations -> f GetDelegations
getDelegations_nextToken = (GetDelegations -> Maybe Text)
-> (GetDelegations -> Maybe Text -> GetDelegations)
-> Lens GetDelegations GetDelegations (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDelegations' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetDelegations' :: GetDelegations -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetDelegations
s@GetDelegations' {} Maybe Text
a -> GetDelegations
s {$sel:nextToken:GetDelegations' :: Maybe Text
nextToken = Maybe Text
a} :: GetDelegations)

-- | Represents the maximum number of results per page, or per API request
-- call.
getDelegations_maxResults :: Lens.Lens' GetDelegations (Prelude.Maybe Prelude.Natural)
getDelegations_maxResults :: (Maybe Natural -> f (Maybe Natural))
-> GetDelegations -> f GetDelegations
getDelegations_maxResults = (GetDelegations -> Maybe Natural)
-> (GetDelegations -> Maybe Natural -> GetDelegations)
-> Lens
     GetDelegations GetDelegations (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDelegations' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:GetDelegations' :: GetDelegations -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: GetDelegations
s@GetDelegations' {} Maybe Natural
a -> GetDelegations
s {$sel:maxResults:GetDelegations' :: Maybe Natural
maxResults = Maybe Natural
a} :: GetDelegations)

instance Core.AWSRequest GetDelegations where
  type
    AWSResponse GetDelegations =
      GetDelegationsResponse
  request :: GetDelegations -> Request GetDelegations
request = Service -> GetDelegations -> Request GetDelegations
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetDelegations
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDelegations)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetDelegations))
-> Logger
-> Service
-> Proxy GetDelegations
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDelegations)))
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 [DelegationMetadata]
-> Maybe Text -> Int -> GetDelegationsResponse
GetDelegationsResponse'
            (Maybe [DelegationMetadata]
 -> Maybe Text -> Int -> GetDelegationsResponse)
-> Either String (Maybe [DelegationMetadata])
-> Either String (Maybe Text -> Int -> GetDelegationsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text -> Either String (Maybe (Maybe [DelegationMetadata]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"delegations" Either String (Maybe (Maybe [DelegationMetadata]))
-> Maybe [DelegationMetadata]
-> Either String (Maybe [DelegationMetadata])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [DelegationMetadata]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Maybe Text -> Int -> GetDelegationsResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetDelegationsResponse)
forall (f :: * -> *) a b. Applicative f => 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 (Int -> GetDelegationsResponse)
-> Either String Int -> Either String GetDelegationsResponse
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 GetDelegations

instance Prelude.NFData GetDelegations

instance Core.ToHeaders GetDelegations where
  toHeaders :: GetDelegations -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetDelegations -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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.ToPath GetDelegations where
  toPath :: GetDelegations -> ByteString
toPath = ByteString -> GetDelegations -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/delegations"

instance Core.ToQuery GetDelegations where
  toQuery :: GetDelegations -> QueryString
toQuery GetDelegations' {Maybe Natural
Maybe Text
maxResults :: Maybe Natural
nextToken :: Maybe Text
$sel:maxResults:GetDelegations' :: GetDelegations -> Maybe Natural
$sel:nextToken:GetDelegations' :: GetDelegations -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"nextToken" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
nextToken,
        ByteString
"maxResults" ByteString -> Maybe Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Natural
maxResults
      ]

-- | /See:/ 'newGetDelegationsResponse' smart constructor.
data GetDelegationsResponse = GetDelegationsResponse'
  { -- | The list of delegations returned by the @GetDelegations@ API.
    GetDelegationsResponse -> Maybe [DelegationMetadata]
delegations :: Prelude.Maybe [DelegationMetadata],
    -- | The pagination token used to fetch the next set of results.
    GetDelegationsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetDelegationsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetDelegationsResponse -> GetDelegationsResponse -> Bool
(GetDelegationsResponse -> GetDelegationsResponse -> Bool)
-> (GetDelegationsResponse -> GetDelegationsResponse -> Bool)
-> Eq GetDelegationsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDelegationsResponse -> GetDelegationsResponse -> Bool
$c/= :: GetDelegationsResponse -> GetDelegationsResponse -> Bool
== :: GetDelegationsResponse -> GetDelegationsResponse -> Bool
$c== :: GetDelegationsResponse -> GetDelegationsResponse -> Bool
Prelude.Eq, ReadPrec [GetDelegationsResponse]
ReadPrec GetDelegationsResponse
Int -> ReadS GetDelegationsResponse
ReadS [GetDelegationsResponse]
(Int -> ReadS GetDelegationsResponse)
-> ReadS [GetDelegationsResponse]
-> ReadPrec GetDelegationsResponse
-> ReadPrec [GetDelegationsResponse]
-> Read GetDelegationsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDelegationsResponse]
$creadListPrec :: ReadPrec [GetDelegationsResponse]
readPrec :: ReadPrec GetDelegationsResponse
$creadPrec :: ReadPrec GetDelegationsResponse
readList :: ReadS [GetDelegationsResponse]
$creadList :: ReadS [GetDelegationsResponse]
readsPrec :: Int -> ReadS GetDelegationsResponse
$creadsPrec :: Int -> ReadS GetDelegationsResponse
Prelude.Read, Int -> GetDelegationsResponse -> ShowS
[GetDelegationsResponse] -> ShowS
GetDelegationsResponse -> String
(Int -> GetDelegationsResponse -> ShowS)
-> (GetDelegationsResponse -> String)
-> ([GetDelegationsResponse] -> ShowS)
-> Show GetDelegationsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDelegationsResponse] -> ShowS
$cshowList :: [GetDelegationsResponse] -> ShowS
show :: GetDelegationsResponse -> String
$cshow :: GetDelegationsResponse -> String
showsPrec :: Int -> GetDelegationsResponse -> ShowS
$cshowsPrec :: Int -> GetDelegationsResponse -> ShowS
Prelude.Show, (forall x. GetDelegationsResponse -> Rep GetDelegationsResponse x)
-> (forall x.
    Rep GetDelegationsResponse x -> GetDelegationsResponse)
-> Generic GetDelegationsResponse
forall x. Rep GetDelegationsResponse x -> GetDelegationsResponse
forall x. GetDelegationsResponse -> Rep GetDelegationsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDelegationsResponse x -> GetDelegationsResponse
$cfrom :: forall x. GetDelegationsResponse -> Rep GetDelegationsResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetDelegationsResponse' 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:
--
-- 'delegations', 'getDelegationsResponse_delegations' - The list of delegations returned by the @GetDelegations@ API.
--
-- 'nextToken', 'getDelegationsResponse_nextToken' - The pagination token used to fetch the next set of results.
--
-- 'httpStatus', 'getDelegationsResponse_httpStatus' - The response's http status code.
newGetDelegationsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDelegationsResponse
newGetDelegationsResponse :: Int -> GetDelegationsResponse
newGetDelegationsResponse Int
pHttpStatus_ =
  GetDelegationsResponse' :: Maybe [DelegationMetadata]
-> Maybe Text -> Int -> GetDelegationsResponse
GetDelegationsResponse'
    { $sel:delegations:GetDelegationsResponse' :: Maybe [DelegationMetadata]
delegations =
        Maybe [DelegationMetadata]
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:GetDelegationsResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDelegationsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of delegations returned by the @GetDelegations@ API.
getDelegationsResponse_delegations :: Lens.Lens' GetDelegationsResponse (Prelude.Maybe [DelegationMetadata])
getDelegationsResponse_delegations :: (Maybe [DelegationMetadata] -> f (Maybe [DelegationMetadata]))
-> GetDelegationsResponse -> f GetDelegationsResponse
getDelegationsResponse_delegations = (GetDelegationsResponse -> Maybe [DelegationMetadata])
-> (GetDelegationsResponse
    -> Maybe [DelegationMetadata] -> GetDelegationsResponse)
-> Lens
     GetDelegationsResponse
     GetDelegationsResponse
     (Maybe [DelegationMetadata])
     (Maybe [DelegationMetadata])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDelegationsResponse' {Maybe [DelegationMetadata]
delegations :: Maybe [DelegationMetadata]
$sel:delegations:GetDelegationsResponse' :: GetDelegationsResponse -> Maybe [DelegationMetadata]
delegations} -> Maybe [DelegationMetadata]
delegations) (\s :: GetDelegationsResponse
s@GetDelegationsResponse' {} Maybe [DelegationMetadata]
a -> GetDelegationsResponse
s {$sel:delegations:GetDelegationsResponse' :: Maybe [DelegationMetadata]
delegations = Maybe [DelegationMetadata]
a} :: GetDelegationsResponse) ((Maybe [DelegationMetadata] -> f (Maybe [DelegationMetadata]))
 -> GetDelegationsResponse -> f GetDelegationsResponse)
-> ((Maybe [DelegationMetadata] -> f (Maybe [DelegationMetadata]))
    -> Maybe [DelegationMetadata] -> f (Maybe [DelegationMetadata]))
-> (Maybe [DelegationMetadata] -> f (Maybe [DelegationMetadata]))
-> GetDelegationsResponse
-> f GetDelegationsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [DelegationMetadata]
  [DelegationMetadata]
  [DelegationMetadata]
  [DelegationMetadata]
-> Iso
     (Maybe [DelegationMetadata])
     (Maybe [DelegationMetadata])
     (Maybe [DelegationMetadata])
     (Maybe [DelegationMetadata])
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
  [DelegationMetadata]
  [DelegationMetadata]
  [DelegationMetadata]
  [DelegationMetadata]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The pagination token used to fetch the next set of results.
getDelegationsResponse_nextToken :: Lens.Lens' GetDelegationsResponse (Prelude.Maybe Prelude.Text)
getDelegationsResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> GetDelegationsResponse -> f GetDelegationsResponse
getDelegationsResponse_nextToken = (GetDelegationsResponse -> Maybe Text)
-> (GetDelegationsResponse -> Maybe Text -> GetDelegationsResponse)
-> Lens
     GetDelegationsResponse
     GetDelegationsResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDelegationsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetDelegationsResponse' :: GetDelegationsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetDelegationsResponse
s@GetDelegationsResponse' {} Maybe Text
a -> GetDelegationsResponse
s {$sel:nextToken:GetDelegationsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: GetDelegationsResponse)

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

instance Prelude.NFData GetDelegationsResponse