packages feed

amazonka-lakeformation-2.0: gen/Amazonka/LakeFormation/GetWorkUnits.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.LakeFormation.GetWorkUnits
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves the work units generated by the @StartQueryPlanning@
-- operation.
--
-- This operation returns paginated results.
module Amazonka.LakeFormation.GetWorkUnits
  ( -- * Creating a Request
    GetWorkUnits (..),
    newGetWorkUnits,

    -- * Request Lenses
    getWorkUnits_nextToken,
    getWorkUnits_pageSize,
    getWorkUnits_queryId,

    -- * Destructuring the Response
    GetWorkUnitsResponse (..),
    newGetWorkUnitsResponse,

    -- * Response Lenses
    getWorkUnitsResponse_nextToken,
    getWorkUnitsResponse_httpStatus,
    getWorkUnitsResponse_queryId,
    getWorkUnitsResponse_workUnitRanges,
  )
where

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

-- | /See:/ 'newGetWorkUnits' smart constructor.
data GetWorkUnits = GetWorkUnits'
  { -- | A continuation token, if this is a continuation call.
    nextToken :: Prelude.Maybe Prelude.Text,
    -- | The size of each page to get in the Amazon Web Services service call.
    -- This does not affect the number of items returned in the command\'s
    -- output. Setting a smaller page size results in more calls to the Amazon
    -- Web Services service, retrieving fewer items in each call. This can help
    -- prevent the Amazon Web Services service calls from timing out.
    pageSize :: Prelude.Maybe Prelude.Int,
    -- | The ID of the plan query operation.
    queryId :: Prelude.Text
  }
  deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic)

-- |
-- Create a value of 'GetWorkUnits' 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', 'getWorkUnits_nextToken' - A continuation token, if this is a continuation call.
--
-- 'pageSize', 'getWorkUnits_pageSize' - The size of each page to get in the Amazon Web Services service call.
-- This does not affect the number of items returned in the command\'s
-- output. Setting a smaller page size results in more calls to the Amazon
-- Web Services service, retrieving fewer items in each call. This can help
-- prevent the Amazon Web Services service calls from timing out.
--
-- 'queryId', 'getWorkUnits_queryId' - The ID of the plan query operation.
newGetWorkUnits ::
  -- | 'queryId'
  Prelude.Text ->
  GetWorkUnits
newGetWorkUnits pQueryId_ =
  GetWorkUnits'
    { nextToken = Prelude.Nothing,
      pageSize = Prelude.Nothing,
      queryId = pQueryId_
    }

-- | A continuation token, if this is a continuation call.
getWorkUnits_nextToken :: Lens.Lens' GetWorkUnits (Prelude.Maybe Prelude.Text)
getWorkUnits_nextToken = Lens.lens (\GetWorkUnits' {nextToken} -> nextToken) (\s@GetWorkUnits' {} a -> s {nextToken = a} :: GetWorkUnits)

-- | The size of each page to get in the Amazon Web Services service call.
-- This does not affect the number of items returned in the command\'s
-- output. Setting a smaller page size results in more calls to the Amazon
-- Web Services service, retrieving fewer items in each call. This can help
-- prevent the Amazon Web Services service calls from timing out.
getWorkUnits_pageSize :: Lens.Lens' GetWorkUnits (Prelude.Maybe Prelude.Int)
getWorkUnits_pageSize = Lens.lens (\GetWorkUnits' {pageSize} -> pageSize) (\s@GetWorkUnits' {} a -> s {pageSize = a} :: GetWorkUnits)

-- | The ID of the plan query operation.
getWorkUnits_queryId :: Lens.Lens' GetWorkUnits Prelude.Text
getWorkUnits_queryId = Lens.lens (\GetWorkUnits' {queryId} -> queryId) (\s@GetWorkUnits' {} a -> s {queryId = a} :: GetWorkUnits)

instance Core.AWSPager GetWorkUnits where
  page rq rs
    | Core.stop
        ( rs
            Lens.^? getWorkUnitsResponse_nextToken
            Prelude.. Lens._Just
        ) =
        Prelude.Nothing
    | Core.stop
        (rs Lens.^. getWorkUnitsResponse_workUnitRanges) =
        Prelude.Nothing
    | Prelude.otherwise =
        Prelude.Just
          Prelude.$ rq
          Prelude.& getWorkUnits_nextToken
          Lens..~ rs
          Lens.^? getWorkUnitsResponse_nextToken
          Prelude.. Lens._Just

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

instance Prelude.Hashable GetWorkUnits where
  hashWithSalt _salt GetWorkUnits' {..} =
    _salt
      `Prelude.hashWithSalt` nextToken
      `Prelude.hashWithSalt` pageSize
      `Prelude.hashWithSalt` queryId

instance Prelude.NFData GetWorkUnits where
  rnf GetWorkUnits' {..} =
    Prelude.rnf nextToken
      `Prelude.seq` Prelude.rnf pageSize
      `Prelude.seq` Prelude.rnf queryId

instance Data.ToHeaders GetWorkUnits where
  toHeaders =
    Prelude.const
      ( Prelude.mconcat
          [ "Content-Type"
              Data.=# ( "application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON GetWorkUnits where
  toJSON GetWorkUnits' {..} =
    Data.object
      ( Prelude.catMaybes
          [ ("NextToken" Data..=) Prelude.<$> nextToken,
            ("PageSize" Data..=) Prelude.<$> pageSize,
            Prelude.Just ("QueryId" Data..= queryId)
          ]
      )

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

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

-- | A structure for the output.
--
-- /See:/ 'newGetWorkUnitsResponse' smart constructor.
data GetWorkUnitsResponse = GetWorkUnitsResponse'
  { -- | A continuation token for paginating the returned list of tokens,
    -- returned if the current segment of the list is not the last.
    nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    httpStatus :: Prelude.Int,
    -- | The ID of the plan query operation.
    queryId :: Prelude.Text,
    -- | A @WorkUnitRangeList@ object that specifies the valid range of work unit
    -- IDs for querying the execution service.
    workUnitRanges :: [WorkUnitRange]
  }
  deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic)

-- |
-- Create a value of 'GetWorkUnitsResponse' 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', 'getWorkUnitsResponse_nextToken' - A continuation token for paginating the returned list of tokens,
-- returned if the current segment of the list is not the last.
--
-- 'httpStatus', 'getWorkUnitsResponse_httpStatus' - The response's http status code.
--
-- 'queryId', 'getWorkUnitsResponse_queryId' - The ID of the plan query operation.
--
-- 'workUnitRanges', 'getWorkUnitsResponse_workUnitRanges' - A @WorkUnitRangeList@ object that specifies the valid range of work unit
-- IDs for querying the execution service.
newGetWorkUnitsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'queryId'
  Prelude.Text ->
  GetWorkUnitsResponse
newGetWorkUnitsResponse pHttpStatus_ pQueryId_ =
  GetWorkUnitsResponse'
    { nextToken = Prelude.Nothing,
      httpStatus = pHttpStatus_,
      queryId = pQueryId_,
      workUnitRanges = Prelude.mempty
    }

-- | A continuation token for paginating the returned list of tokens,
-- returned if the current segment of the list is not the last.
getWorkUnitsResponse_nextToken :: Lens.Lens' GetWorkUnitsResponse (Prelude.Maybe Prelude.Text)
getWorkUnitsResponse_nextToken = Lens.lens (\GetWorkUnitsResponse' {nextToken} -> nextToken) (\s@GetWorkUnitsResponse' {} a -> s {nextToken = a} :: GetWorkUnitsResponse)

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

-- | The ID of the plan query operation.
getWorkUnitsResponse_queryId :: Lens.Lens' GetWorkUnitsResponse Prelude.Text
getWorkUnitsResponse_queryId = Lens.lens (\GetWorkUnitsResponse' {queryId} -> queryId) (\s@GetWorkUnitsResponse' {} a -> s {queryId = a} :: GetWorkUnitsResponse)

-- | A @WorkUnitRangeList@ object that specifies the valid range of work unit
-- IDs for querying the execution service.
getWorkUnitsResponse_workUnitRanges :: Lens.Lens' GetWorkUnitsResponse [WorkUnitRange]
getWorkUnitsResponse_workUnitRanges = Lens.lens (\GetWorkUnitsResponse' {workUnitRanges} -> workUnitRanges) (\s@GetWorkUnitsResponse' {} a -> s {workUnitRanges = a} :: GetWorkUnitsResponse) Prelude.. Lens.coerced

instance Prelude.NFData GetWorkUnitsResponse where
  rnf GetWorkUnitsResponse' {..} =
    Prelude.rnf nextToken
      `Prelude.seq` Prelude.rnf httpStatus
      `Prelude.seq` Prelude.rnf queryId
      `Prelude.seq` Prelude.rnf workUnitRanges