{-# 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.DeviceFarm.ListRuns
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets information about runs, given an AWS Device Farm project ARN.
--
-- This operation returns paginated results.
module Amazonka.DeviceFarm.ListRuns
  ( -- * Creating a Request
    ListRuns (..),
    newListRuns,

    -- * Request Lenses
    listRuns_nextToken,
    listRuns_arn,

    -- * Destructuring the Response
    ListRunsResponse (..),
    newListRunsResponse,

    -- * Response Lenses
    listRunsResponse_nextToken,
    listRunsResponse_runs,
    listRunsResponse_httpStatus,
  )
where

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

-- | Represents a request to the list runs operation.
--
-- /See:/ 'newListRuns' smart constructor.
data ListRuns = ListRuns'
  { -- | An identifier that was returned from the previous call to this
    -- operation, which can be used to return the next set of items in the
    -- list.
    ListRuns -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the project for which you want to list
    -- runs.
    ListRuns -> Text
arn :: Prelude.Text
  }
  deriving (ListRuns -> ListRuns -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListRuns -> ListRuns -> Bool
$c/= :: ListRuns -> ListRuns -> Bool
== :: ListRuns -> ListRuns -> Bool
$c== :: ListRuns -> ListRuns -> Bool
Prelude.Eq, ReadPrec [ListRuns]
ReadPrec ListRuns
Int -> ReadS ListRuns
ReadS [ListRuns]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListRuns]
$creadListPrec :: ReadPrec [ListRuns]
readPrec :: ReadPrec ListRuns
$creadPrec :: ReadPrec ListRuns
readList :: ReadS [ListRuns]
$creadList :: ReadS [ListRuns]
readsPrec :: Int -> ReadS ListRuns
$creadsPrec :: Int -> ReadS ListRuns
Prelude.Read, Int -> ListRuns -> ShowS
[ListRuns] -> ShowS
ListRuns -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListRuns] -> ShowS
$cshowList :: [ListRuns] -> ShowS
show :: ListRuns -> String
$cshow :: ListRuns -> String
showsPrec :: Int -> ListRuns -> ShowS
$cshowsPrec :: Int -> ListRuns -> ShowS
Prelude.Show, forall x. Rep ListRuns x -> ListRuns
forall x. ListRuns -> Rep ListRuns x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListRuns x -> ListRuns
$cfrom :: forall x. ListRuns -> Rep ListRuns x
Prelude.Generic)

-- |
-- Create a value of 'ListRuns' 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', 'listRuns_nextToken' - An identifier that was returned from the previous call to this
-- operation, which can be used to return the next set of items in the
-- list.
--
-- 'arn', 'listRuns_arn' - The Amazon Resource Name (ARN) of the project for which you want to list
-- runs.
newListRuns ::
  -- | 'arn'
  Prelude.Text ->
  ListRuns
newListRuns :: Text -> ListRuns
newListRuns Text
pArn_ =
  ListRuns' {$sel:nextToken:ListRuns' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing, $sel:arn:ListRuns' :: Text
arn = Text
pArn_}

-- | An identifier that was returned from the previous call to this
-- operation, which can be used to return the next set of items in the
-- list.
listRuns_nextToken :: Lens.Lens' ListRuns (Prelude.Maybe Prelude.Text)
listRuns_nextToken :: Lens' ListRuns (Maybe Text)
listRuns_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRuns' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListRuns' :: ListRuns -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListRuns
s@ListRuns' {} Maybe Text
a -> ListRuns
s {$sel:nextToken:ListRuns' :: Maybe Text
nextToken = Maybe Text
a} :: ListRuns)

-- | The Amazon Resource Name (ARN) of the project for which you want to list
-- runs.
listRuns_arn :: Lens.Lens' ListRuns Prelude.Text
listRuns_arn :: Lens' ListRuns Text
listRuns_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRuns' {Text
arn :: Text
$sel:arn:ListRuns' :: ListRuns -> Text
arn} -> Text
arn) (\s :: ListRuns
s@ListRuns' {} Text
a -> ListRuns
s {$sel:arn:ListRuns' :: Text
arn = Text
a} :: ListRuns)

instance Core.AWSPager ListRuns where
  page :: ListRuns -> AWSResponse ListRuns -> Maybe ListRuns
page ListRuns
rq AWSResponse ListRuns
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListRuns
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRunsResponse (Maybe Text)
listRunsResponse_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 ListRuns
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRunsResponse (Maybe [Run])
listRunsResponse_runs
            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.$ ListRuns
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListRuns (Maybe Text)
listRuns_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListRuns
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRunsResponse (Maybe Text)
listRunsResponse_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 ListRuns where
  type AWSResponse ListRuns = ListRunsResponse
  request :: (Service -> Service) -> ListRuns -> Request ListRuns
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListRuns
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListRuns)))
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 [Run] -> Int -> ListRunsResponse
ListRunsResponse'
            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
"runs" 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 ListRuns where
  hashWithSalt :: Int -> ListRuns -> Int
hashWithSalt Int
_salt ListRuns' {Maybe Text
Text
arn :: Text
nextToken :: Maybe Text
$sel:arn:ListRuns' :: ListRuns -> Text
$sel:nextToken:ListRuns' :: ListRuns -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn

instance Prelude.NFData ListRuns where
  rnf :: ListRuns -> ()
rnf ListRuns' {Maybe Text
Text
arn :: Text
nextToken :: Maybe Text
$sel:arn:ListRuns' :: ListRuns -> Text
$sel:nextToken:ListRuns' :: ListRuns -> 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 Text
arn

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

instance Data.ToJSON ListRuns where
  toJSON :: ListRuns -> Value
toJSON ListRuns' {Maybe Text
Text
arn :: Text
nextToken :: Maybe Text
$sel:arn:ListRuns' :: ListRuns -> Text
$sel:nextToken:ListRuns' :: ListRuns -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"nextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            forall a. a -> Maybe a
Prelude.Just (Key
"arn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
arn)
          ]
      )

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

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

-- | Represents the result of a list runs request.
--
-- /See:/ 'newListRunsResponse' smart constructor.
data ListRunsResponse = ListRunsResponse'
  { -- | If the number of items that are returned is significantly large, this is
    -- an identifier that is also returned. It can be used in a subsequent call
    -- to this operation to return the next set of items in the list.
    ListRunsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Information about the runs.
    ListRunsResponse -> Maybe [Run]
runs :: Prelude.Maybe [Run],
    -- | The response's http status code.
    ListRunsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListRunsResponse -> ListRunsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListRunsResponse -> ListRunsResponse -> Bool
$c/= :: ListRunsResponse -> ListRunsResponse -> Bool
== :: ListRunsResponse -> ListRunsResponse -> Bool
$c== :: ListRunsResponse -> ListRunsResponse -> Bool
Prelude.Eq, ReadPrec [ListRunsResponse]
ReadPrec ListRunsResponse
Int -> ReadS ListRunsResponse
ReadS [ListRunsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListRunsResponse]
$creadListPrec :: ReadPrec [ListRunsResponse]
readPrec :: ReadPrec ListRunsResponse
$creadPrec :: ReadPrec ListRunsResponse
readList :: ReadS [ListRunsResponse]
$creadList :: ReadS [ListRunsResponse]
readsPrec :: Int -> ReadS ListRunsResponse
$creadsPrec :: Int -> ReadS ListRunsResponse
Prelude.Read, Int -> ListRunsResponse -> ShowS
[ListRunsResponse] -> ShowS
ListRunsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListRunsResponse] -> ShowS
$cshowList :: [ListRunsResponse] -> ShowS
show :: ListRunsResponse -> String
$cshow :: ListRunsResponse -> String
showsPrec :: Int -> ListRunsResponse -> ShowS
$cshowsPrec :: Int -> ListRunsResponse -> ShowS
Prelude.Show, forall x. Rep ListRunsResponse x -> ListRunsResponse
forall x. ListRunsResponse -> Rep ListRunsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListRunsResponse x -> ListRunsResponse
$cfrom :: forall x. ListRunsResponse -> Rep ListRunsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListRunsResponse' 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', 'listRunsResponse_nextToken' - If the number of items that are returned is significantly large, this is
-- an identifier that is also returned. It can be used in a subsequent call
-- to this operation to return the next set of items in the list.
--
-- 'runs', 'listRunsResponse_runs' - Information about the runs.
--
-- 'httpStatus', 'listRunsResponse_httpStatus' - The response's http status code.
newListRunsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListRunsResponse
newListRunsResponse :: Int -> ListRunsResponse
newListRunsResponse Int
pHttpStatus_ =
  ListRunsResponse'
    { $sel:nextToken:ListRunsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:runs:ListRunsResponse' :: Maybe [Run]
runs = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListRunsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If the number of items that are returned is significantly large, this is
-- an identifier that is also returned. It can be used in a subsequent call
-- to this operation to return the next set of items in the list.
listRunsResponse_nextToken :: Lens.Lens' ListRunsResponse (Prelude.Maybe Prelude.Text)
listRunsResponse_nextToken :: Lens' ListRunsResponse (Maybe Text)
listRunsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRunsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListRunsResponse' :: ListRunsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListRunsResponse
s@ListRunsResponse' {} Maybe Text
a -> ListRunsResponse
s {$sel:nextToken:ListRunsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListRunsResponse)

-- | Information about the runs.
listRunsResponse_runs :: Lens.Lens' ListRunsResponse (Prelude.Maybe [Run])
listRunsResponse_runs :: Lens' ListRunsResponse (Maybe [Run])
listRunsResponse_runs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRunsResponse' {Maybe [Run]
runs :: Maybe [Run]
$sel:runs:ListRunsResponse' :: ListRunsResponse -> Maybe [Run]
runs} -> Maybe [Run]
runs) (\s :: ListRunsResponse
s@ListRunsResponse' {} Maybe [Run]
a -> ListRunsResponse
s {$sel:runs:ListRunsResponse' :: Maybe [Run]
runs = Maybe [Run]
a} :: ListRunsResponse) 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.
listRunsResponse_httpStatus :: Lens.Lens' ListRunsResponse Prelude.Int
listRunsResponse_httpStatus :: Lens' ListRunsResponse Int
listRunsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRunsResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListRunsResponse' :: ListRunsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListRunsResponse
s@ListRunsResponse' {} Int
a -> ListRunsResponse
s {$sel:httpStatus:ListRunsResponse' :: Int
httpStatus = Int
a} :: ListRunsResponse)

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