packages feed

amazonka-organizations-2.0: gen/Amazonka/Organizations/ListHandshakesForAccount.hs

{-# 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.ListHandshakesForAccount
-- 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 current handshakes that are associated with the account of the
-- requesting user.
--
-- Handshakes that are @ACCEPTED@, @DECLINED@, @CANCELED@, or @EXPIRED@
-- appear in the results of this API for only 30 days after changing to
-- that state. After that, they\'re deleted and no longer accessible.
--
-- 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 from any account in the organization.
--
-- This operation returns paginated results.
module Amazonka.Organizations.ListHandshakesForAccount
  ( -- * Creating a Request
    ListHandshakesForAccount (..),
    newListHandshakesForAccount,

    -- * Request Lenses
    listHandshakesForAccount_filter,
    listHandshakesForAccount_maxResults,
    listHandshakesForAccount_nextToken,

    -- * Destructuring the Response
    ListHandshakesForAccountResponse (..),
    newListHandshakesForAccountResponse,

    -- * Response Lenses
    listHandshakesForAccountResponse_handshakes,
    listHandshakesForAccountResponse_nextToken,
    listHandshakesForAccountResponse_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:/ 'newListHandshakesForAccount' smart constructor.
data ListHandshakesForAccount = ListHandshakesForAccount'
  { -- | Filters the handshakes that you want included in the response. The
    -- default is all types. Use the @ActionType@ element to limit the output
    -- to only a specified type, such as @INVITE@, @ENABLE_ALL_FEATURES@, or
    -- @APPROVE_ALL_FEATURES@. Alternatively, for the @ENABLE_ALL_FEATURES@
    -- handshake that generates a separate child handshake for each member
    -- account, you can specify @ParentHandshakeId@ to see only the handshakes
    -- that were generated by that parent request.
    filter' :: Prelude.Maybe HandshakeFilter,
    -- | 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.
    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.
    nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic)

-- |
-- Create a value of 'ListHandshakesForAccount' 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:
--
-- 'filter'', 'listHandshakesForAccount_filter' - Filters the handshakes that you want included in the response. The
-- default is all types. Use the @ActionType@ element to limit the output
-- to only a specified type, such as @INVITE@, @ENABLE_ALL_FEATURES@, or
-- @APPROVE_ALL_FEATURES@. Alternatively, for the @ENABLE_ALL_FEATURES@
-- handshake that generates a separate child handshake for each member
-- account, you can specify @ParentHandshakeId@ to see only the handshakes
-- that were generated by that parent request.
--
-- 'maxResults', 'listHandshakesForAccount_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', 'listHandshakesForAccount_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.
newListHandshakesForAccount ::
  ListHandshakesForAccount
newListHandshakesForAccount =
  ListHandshakesForAccount'
    { filter' =
        Prelude.Nothing,
      maxResults = Prelude.Nothing,
      nextToken = Prelude.Nothing
    }

-- | Filters the handshakes that you want included in the response. The
-- default is all types. Use the @ActionType@ element to limit the output
-- to only a specified type, such as @INVITE@, @ENABLE_ALL_FEATURES@, or
-- @APPROVE_ALL_FEATURES@. Alternatively, for the @ENABLE_ALL_FEATURES@
-- handshake that generates a separate child handshake for each member
-- account, you can specify @ParentHandshakeId@ to see only the handshakes
-- that were generated by that parent request.
listHandshakesForAccount_filter :: Lens.Lens' ListHandshakesForAccount (Prelude.Maybe HandshakeFilter)
listHandshakesForAccount_filter = Lens.lens (\ListHandshakesForAccount' {filter'} -> filter') (\s@ListHandshakesForAccount' {} a -> s {filter' = a} :: ListHandshakesForAccount)

-- | 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.
listHandshakesForAccount_maxResults :: Lens.Lens' ListHandshakesForAccount (Prelude.Maybe Prelude.Natural)
listHandshakesForAccount_maxResults = Lens.lens (\ListHandshakesForAccount' {maxResults} -> maxResults) (\s@ListHandshakesForAccount' {} a -> s {maxResults = a} :: ListHandshakesForAccount)

-- | 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.
listHandshakesForAccount_nextToken :: Lens.Lens' ListHandshakesForAccount (Prelude.Maybe Prelude.Text)
listHandshakesForAccount_nextToken = Lens.lens (\ListHandshakesForAccount' {nextToken} -> nextToken) (\s@ListHandshakesForAccount' {} a -> s {nextToken = a} :: ListHandshakesForAccount)

instance Core.AWSPager ListHandshakesForAccount where
  page rq rs
    | Core.stop
        ( rs
            Lens.^? listHandshakesForAccountResponse_nextToken
            Prelude.. Lens._Just
        ) =
        Prelude.Nothing
    | Core.stop
        ( rs
            Lens.^? listHandshakesForAccountResponse_handshakes
            Prelude.. Lens._Just
        ) =
        Prelude.Nothing
    | Prelude.otherwise =
        Prelude.Just
          Prelude.$ rq
          Prelude.& listHandshakesForAccount_nextToken
          Lens..~ rs
          Lens.^? listHandshakesForAccountResponse_nextToken
          Prelude.. Lens._Just

instance Core.AWSRequest ListHandshakesForAccount where
  type
    AWSResponse ListHandshakesForAccount =
      ListHandshakesForAccountResponse
  request overrides =
    Request.postJSON (overrides defaultService)
  response =
    Response.receiveJSON
      ( \s h x ->
          ListHandshakesForAccountResponse'
            Prelude.<$> (x Data..?> "Handshakes" Core..!@ Prelude.mempty)
            Prelude.<*> (x Data..?> "NextToken")
            Prelude.<*> (Prelude.pure (Prelude.fromEnum s))
      )

instance Prelude.Hashable ListHandshakesForAccount where
  hashWithSalt _salt ListHandshakesForAccount' {..} =
    _salt
      `Prelude.hashWithSalt` filter'
      `Prelude.hashWithSalt` maxResults
      `Prelude.hashWithSalt` nextToken

instance Prelude.NFData ListHandshakesForAccount where
  rnf ListHandshakesForAccount' {..} =
    Prelude.rnf filter'
      `Prelude.seq` Prelude.rnf maxResults
      `Prelude.seq` Prelude.rnf nextToken

instance Data.ToHeaders ListHandshakesForAccount where
  toHeaders =
    Prelude.const
      ( Prelude.mconcat
          [ "X-Amz-Target"
              Data.=# ( "AWSOrganizationsV20161128.ListHandshakesForAccount" ::
                          Prelude.ByteString
                      ),
            "Content-Type"
              Data.=# ( "application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ListHandshakesForAccount where
  toJSON ListHandshakesForAccount' {..} =
    Data.object
      ( Prelude.catMaybes
          [ ("Filter" Data..=) Prelude.<$> filter',
            ("MaxResults" Data..=) Prelude.<$> maxResults,
            ("NextToken" Data..=) Prelude.<$> nextToken
          ]
      )

instance Data.ToPath ListHandshakesForAccount where
  toPath = Prelude.const "/"

instance Data.ToQuery ListHandshakesForAccount where
  toQuery = Prelude.const Prelude.mempty

-- | /See:/ 'newListHandshakesForAccountResponse' smart constructor.
data ListHandshakesForAccountResponse = ListHandshakesForAccountResponse'
  { -- | A list of Handshake objects with details about each of the handshakes
    -- that is associated with the specified account.
    handshakes :: Prelude.Maybe [Handshake],
    -- | 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@.
    nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    httpStatus :: Prelude.Int
  }
  deriving (Prelude.Eq, Prelude.Show, Prelude.Generic)

-- |
-- Create a value of 'ListHandshakesForAccountResponse' 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:
--
-- 'handshakes', 'listHandshakesForAccountResponse_handshakes' - A list of Handshake objects with details about each of the handshakes
-- that is associated with the specified account.
--
-- 'nextToken', 'listHandshakesForAccountResponse_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@.
--
-- 'httpStatus', 'listHandshakesForAccountResponse_httpStatus' - The response's http status code.
newListHandshakesForAccountResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListHandshakesForAccountResponse
newListHandshakesForAccountResponse pHttpStatus_ =
  ListHandshakesForAccountResponse'
    { handshakes =
        Prelude.Nothing,
      nextToken = Prelude.Nothing,
      httpStatus = pHttpStatus_
    }

-- | A list of Handshake objects with details about each of the handshakes
-- that is associated with the specified account.
listHandshakesForAccountResponse_handshakes :: Lens.Lens' ListHandshakesForAccountResponse (Prelude.Maybe [Handshake])
listHandshakesForAccountResponse_handshakes = Lens.lens (\ListHandshakesForAccountResponse' {handshakes} -> handshakes) (\s@ListHandshakesForAccountResponse' {} a -> s {handshakes = a} :: ListHandshakesForAccountResponse) Prelude.. Lens.mapping Lens.coerced

-- | 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@.
listHandshakesForAccountResponse_nextToken :: Lens.Lens' ListHandshakesForAccountResponse (Prelude.Maybe Prelude.Text)
listHandshakesForAccountResponse_nextToken = Lens.lens (\ListHandshakesForAccountResponse' {nextToken} -> nextToken) (\s@ListHandshakesForAccountResponse' {} a -> s {nextToken = a} :: ListHandshakesForAccountResponse)

-- | The response's http status code.
listHandshakesForAccountResponse_httpStatus :: Lens.Lens' ListHandshakesForAccountResponse Prelude.Int
listHandshakesForAccountResponse_httpStatus = Lens.lens (\ListHandshakesForAccountResponse' {httpStatus} -> httpStatus) (\s@ListHandshakesForAccountResponse' {} a -> s {httpStatus = a} :: ListHandshakesForAccountResponse)

instance
  Prelude.NFData
    ListHandshakesForAccountResponse
  where
  rnf ListHandshakesForAccountResponse' {..} =
    Prelude.rnf handshakes
      `Prelude.seq` Prelude.rnf nextToken
      `Prelude.seq` Prelude.rnf httpStatus