{-# 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.SnowDeviceManagement.ListTasks
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns a list of tasks that can be filtered by state.
--
-- This operation returns paginated results.
module Amazonka.SnowDeviceManagement.ListTasks
  ( -- * Creating a Request
    ListTasks (..),
    newListTasks,

    -- * Request Lenses
    listTasks_maxResults,
    listTasks_nextToken,
    listTasks_state,

    -- * Destructuring the Response
    ListTasksResponse (..),
    newListTasksResponse,

    -- * Response Lenses
    listTasksResponse_nextToken,
    listTasksResponse_tasks,
    listTasksResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListTasks' smart constructor.
data ListTasks = ListTasks'
  { -- | The maximum number of tasks per page.
    ListTasks -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | A pagination token to continue to the next page of tasks.
    ListTasks -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A structure used to filter the list of tasks.
    ListTasks -> Maybe TaskState
state :: Prelude.Maybe TaskState
  }
  deriving (ListTasks -> ListTasks -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTasks -> ListTasks -> Bool
$c/= :: ListTasks -> ListTasks -> Bool
== :: ListTasks -> ListTasks -> Bool
$c== :: ListTasks -> ListTasks -> Bool
Prelude.Eq, ReadPrec [ListTasks]
ReadPrec ListTasks
Int -> ReadS ListTasks
ReadS [ListTasks]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTasks]
$creadListPrec :: ReadPrec [ListTasks]
readPrec :: ReadPrec ListTasks
$creadPrec :: ReadPrec ListTasks
readList :: ReadS [ListTasks]
$creadList :: ReadS [ListTasks]
readsPrec :: Int -> ReadS ListTasks
$creadsPrec :: Int -> ReadS ListTasks
Prelude.Read, Int -> ListTasks -> ShowS
[ListTasks] -> ShowS
ListTasks -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTasks] -> ShowS
$cshowList :: [ListTasks] -> ShowS
show :: ListTasks -> String
$cshow :: ListTasks -> String
showsPrec :: Int -> ListTasks -> ShowS
$cshowsPrec :: Int -> ListTasks -> ShowS
Prelude.Show, forall x. Rep ListTasks x -> ListTasks
forall x. ListTasks -> Rep ListTasks x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTasks x -> ListTasks
$cfrom :: forall x. ListTasks -> Rep ListTasks x
Prelude.Generic)

-- |
-- Create a value of 'ListTasks' 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', 'listTasks_maxResults' - The maximum number of tasks per page.
--
-- 'nextToken', 'listTasks_nextToken' - A pagination token to continue to the next page of tasks.
--
-- 'state', 'listTasks_state' - A structure used to filter the list of tasks.
newListTasks ::
  ListTasks
newListTasks :: ListTasks
newListTasks =
  ListTasks'
    { $sel:maxResults:ListTasks' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListTasks' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:state:ListTasks' :: Maybe TaskState
state = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of tasks per page.
listTasks_maxResults :: Lens.Lens' ListTasks (Prelude.Maybe Prelude.Natural)
listTasks_maxResults :: Lens' ListTasks (Maybe Natural)
listTasks_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTasks' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListTasks' :: ListTasks -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListTasks
s@ListTasks' {} Maybe Natural
a -> ListTasks
s {$sel:maxResults:ListTasks' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListTasks)

-- | A pagination token to continue to the next page of tasks.
listTasks_nextToken :: Lens.Lens' ListTasks (Prelude.Maybe Prelude.Text)
listTasks_nextToken :: Lens' ListTasks (Maybe Text)
listTasks_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTasks' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTasks' :: ListTasks -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTasks
s@ListTasks' {} Maybe Text
a -> ListTasks
s {$sel:nextToken:ListTasks' :: Maybe Text
nextToken = Maybe Text
a} :: ListTasks)

-- | A structure used to filter the list of tasks.
listTasks_state :: Lens.Lens' ListTasks (Prelude.Maybe TaskState)
listTasks_state :: Lens' ListTasks (Maybe TaskState)
listTasks_state = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTasks' {Maybe TaskState
state :: Maybe TaskState
$sel:state:ListTasks' :: ListTasks -> Maybe TaskState
state} -> Maybe TaskState
state) (\s :: ListTasks
s@ListTasks' {} Maybe TaskState
a -> ListTasks
s {$sel:state:ListTasks' :: Maybe TaskState
state = Maybe TaskState
a} :: ListTasks)

instance Core.AWSPager ListTasks where
  page :: ListTasks -> AWSResponse ListTasks -> Maybe ListTasks
page ListTasks
rq AWSResponse ListTasks
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListTasks
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListTasksResponse (Maybe Text)
listTasksResponse_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 ListTasks
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListTasksResponse (Maybe [TaskSummary])
listTasksResponse_tasks
            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.$ ListTasks
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListTasks (Maybe Text)
listTasks_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListTasks
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListTasksResponse (Maybe Text)
listTasksResponse_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 ListTasks where
  type AWSResponse ListTasks = ListTasksResponse
  request :: (Service -> Service) -> ListTasks -> Request ListTasks
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListTasks
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListTasks)))
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 [TaskSummary] -> Int -> ListTasksResponse
ListTasksResponse'
            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
"tasks" 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 ListTasks where
  hashWithSalt :: Int -> ListTasks -> Int
hashWithSalt Int
_salt ListTasks' {Maybe Natural
Maybe Text
Maybe TaskState
state :: Maybe TaskState
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:state:ListTasks' :: ListTasks -> Maybe TaskState
$sel:nextToken:ListTasks' :: ListTasks -> Maybe Text
$sel:maxResults:ListTasks' :: ListTasks -> 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` Maybe TaskState
state

instance Prelude.NFData ListTasks where
  rnf :: ListTasks -> ()
rnf ListTasks' {Maybe Natural
Maybe Text
Maybe TaskState
state :: Maybe TaskState
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:state:ListTasks' :: ListTasks -> Maybe TaskState
$sel:nextToken:ListTasks' :: ListTasks -> Maybe Text
$sel:maxResults:ListTasks' :: ListTasks -> 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 Maybe TaskState
state

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

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

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

-- | /See:/ 'newListTasksResponse' smart constructor.
data ListTasksResponse = ListTasksResponse'
  { -- | A pagination token to continue to the next page of tasks.
    ListTasksResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A list of task structures containing details about each task.
    ListTasksResponse -> Maybe [TaskSummary]
tasks :: Prelude.Maybe [TaskSummary],
    -- | The response's http status code.
    ListTasksResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListTasksResponse -> ListTasksResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTasksResponse -> ListTasksResponse -> Bool
$c/= :: ListTasksResponse -> ListTasksResponse -> Bool
== :: ListTasksResponse -> ListTasksResponse -> Bool
$c== :: ListTasksResponse -> ListTasksResponse -> Bool
Prelude.Eq, ReadPrec [ListTasksResponse]
ReadPrec ListTasksResponse
Int -> ReadS ListTasksResponse
ReadS [ListTasksResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTasksResponse]
$creadListPrec :: ReadPrec [ListTasksResponse]
readPrec :: ReadPrec ListTasksResponse
$creadPrec :: ReadPrec ListTasksResponse
readList :: ReadS [ListTasksResponse]
$creadList :: ReadS [ListTasksResponse]
readsPrec :: Int -> ReadS ListTasksResponse
$creadsPrec :: Int -> ReadS ListTasksResponse
Prelude.Read, Int -> ListTasksResponse -> ShowS
[ListTasksResponse] -> ShowS
ListTasksResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTasksResponse] -> ShowS
$cshowList :: [ListTasksResponse] -> ShowS
show :: ListTasksResponse -> String
$cshow :: ListTasksResponse -> String
showsPrec :: Int -> ListTasksResponse -> ShowS
$cshowsPrec :: Int -> ListTasksResponse -> ShowS
Prelude.Show, forall x. Rep ListTasksResponse x -> ListTasksResponse
forall x. ListTasksResponse -> Rep ListTasksResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTasksResponse x -> ListTasksResponse
$cfrom :: forall x. ListTasksResponse -> Rep ListTasksResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListTasksResponse' 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', 'listTasksResponse_nextToken' - A pagination token to continue to the next page of tasks.
--
-- 'tasks', 'listTasksResponse_tasks' - A list of task structures containing details about each task.
--
-- 'httpStatus', 'listTasksResponse_httpStatus' - The response's http status code.
newListTasksResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListTasksResponse
newListTasksResponse :: Int -> ListTasksResponse
newListTasksResponse Int
pHttpStatus_ =
  ListTasksResponse'
    { $sel:nextToken:ListTasksResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:tasks:ListTasksResponse' :: Maybe [TaskSummary]
tasks = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListTasksResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A pagination token to continue to the next page of tasks.
listTasksResponse_nextToken :: Lens.Lens' ListTasksResponse (Prelude.Maybe Prelude.Text)
listTasksResponse_nextToken :: Lens' ListTasksResponse (Maybe Text)
listTasksResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTasksResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTasksResponse' :: ListTasksResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTasksResponse
s@ListTasksResponse' {} Maybe Text
a -> ListTasksResponse
s {$sel:nextToken:ListTasksResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListTasksResponse)

-- | A list of task structures containing details about each task.
listTasksResponse_tasks :: Lens.Lens' ListTasksResponse (Prelude.Maybe [TaskSummary])
listTasksResponse_tasks :: Lens' ListTasksResponse (Maybe [TaskSummary])
listTasksResponse_tasks = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTasksResponse' {Maybe [TaskSummary]
tasks :: Maybe [TaskSummary]
$sel:tasks:ListTasksResponse' :: ListTasksResponse -> Maybe [TaskSummary]
tasks} -> Maybe [TaskSummary]
tasks) (\s :: ListTasksResponse
s@ListTasksResponse' {} Maybe [TaskSummary]
a -> ListTasksResponse
s {$sel:tasks:ListTasksResponse' :: Maybe [TaskSummary]
tasks = Maybe [TaskSummary]
a} :: ListTasksResponse) 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.
listTasksResponse_httpStatus :: Lens.Lens' ListTasksResponse Prelude.Int
listTasksResponse_httpStatus :: Lens' ListTasksResponse Int
listTasksResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTasksResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListTasksResponse' :: ListTasksResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListTasksResponse
s@ListTasksResponse' {} Int
a -> ListTasksResponse
s {$sel:httpStatus:ListTasksResponse' :: Int
httpStatus = Int
a} :: ListTasksResponse)

instance Prelude.NFData ListTasksResponse where
  rnf :: ListTasksResponse -> ()
rnf ListTasksResponse' {Int
Maybe [TaskSummary]
Maybe Text
httpStatus :: Int
tasks :: Maybe [TaskSummary]
nextToken :: Maybe Text
$sel:httpStatus:ListTasksResponse' :: ListTasksResponse -> Int
$sel:tasks:ListTasksResponse' :: ListTasksResponse -> Maybe [TaskSummary]
$sel:nextToken:ListTasksResponse' :: ListTasksResponse -> 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 [TaskSummary]
tasks
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus