{-# 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.ListTests
-- 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 tests in a given test suite.
--
-- This operation returns paginated results.
module Amazonka.DeviceFarm.ListTests
  ( -- * Creating a Request
    ListTests (..),
    newListTests,

    -- * Request Lenses
    listTests_nextToken,
    listTests_arn,

    -- * Destructuring the Response
    ListTestsResponse (..),
    newListTestsResponse,

    -- * Response Lenses
    listTestsResponse_nextToken,
    listTestsResponse_tests,
    listTestsResponse_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 tests operation.
--
-- /See:/ 'newListTests' smart constructor.
data ListTests = ListTests'
  { -- | 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.
    ListTests -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The test suite\'s Amazon Resource Name (ARN).
    ListTests -> Text
arn :: Prelude.Text
  }
  deriving (ListTests -> ListTests -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTests -> ListTests -> Bool
$c/= :: ListTests -> ListTests -> Bool
== :: ListTests -> ListTests -> Bool
$c== :: ListTests -> ListTests -> Bool
Prelude.Eq, ReadPrec [ListTests]
ReadPrec ListTests
Int -> ReadS ListTests
ReadS [ListTests]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTests]
$creadListPrec :: ReadPrec [ListTests]
readPrec :: ReadPrec ListTests
$creadPrec :: ReadPrec ListTests
readList :: ReadS [ListTests]
$creadList :: ReadS [ListTests]
readsPrec :: Int -> ReadS ListTests
$creadsPrec :: Int -> ReadS ListTests
Prelude.Read, Int -> ListTests -> ShowS
[ListTests] -> ShowS
ListTests -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTests] -> ShowS
$cshowList :: [ListTests] -> ShowS
show :: ListTests -> String
$cshow :: ListTests -> String
showsPrec :: Int -> ListTests -> ShowS
$cshowsPrec :: Int -> ListTests -> ShowS
Prelude.Show, forall x. Rep ListTests x -> ListTests
forall x. ListTests -> Rep ListTests x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTests x -> ListTests
$cfrom :: forall x. ListTests -> Rep ListTests x
Prelude.Generic)

-- |
-- Create a value of 'ListTests' 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', 'listTests_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', 'listTests_arn' - The test suite\'s Amazon Resource Name (ARN).
newListTests ::
  -- | 'arn'
  Prelude.Text ->
  ListTests
newListTests :: Text -> ListTests
newListTests Text
pArn_ =
  ListTests'
    { $sel:nextToken:ListTests' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:arn:ListTests' :: 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.
listTests_nextToken :: Lens.Lens' ListTests (Prelude.Maybe Prelude.Text)
listTests_nextToken :: Lens' ListTests (Maybe Text)
listTests_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTests' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTests' :: ListTests -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTests
s@ListTests' {} Maybe Text
a -> ListTests
s {$sel:nextToken:ListTests' :: Maybe Text
nextToken = Maybe Text
a} :: ListTests)

-- | The test suite\'s Amazon Resource Name (ARN).
listTests_arn :: Lens.Lens' ListTests Prelude.Text
listTests_arn :: Lens' ListTests Text
listTests_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTests' {Text
arn :: Text
$sel:arn:ListTests' :: ListTests -> Text
arn} -> Text
arn) (\s :: ListTests
s@ListTests' {} Text
a -> ListTests
s {$sel:arn:ListTests' :: Text
arn = Text
a} :: ListTests)

instance Core.AWSPager ListTests where
  page :: ListTests -> AWSResponse ListTests -> Maybe ListTests
page ListTests
rq AWSResponse ListTests
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListTests
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListTestsResponse (Maybe Text)
listTestsResponse_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 ListTests
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListTestsResponse (Maybe [Test])
listTestsResponse_tests
            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.$ ListTests
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListTests (Maybe Text)
listTests_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListTests
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListTestsResponse (Maybe Text)
listTestsResponse_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 ListTests where
  type AWSResponse ListTests = ListTestsResponse
  request :: (Service -> Service) -> ListTests -> Request ListTests
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 ListTests
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListTests)))
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 [Test] -> Int -> ListTestsResponse
ListTestsResponse'
            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
"tests" 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 ListTests where
  hashWithSalt :: Int -> ListTests -> Int
hashWithSalt Int
_salt ListTests' {Maybe Text
Text
arn :: Text
nextToken :: Maybe Text
$sel:arn:ListTests' :: ListTests -> Text
$sel:nextToken:ListTests' :: ListTests -> 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 ListTests where
  rnf :: ListTests -> ()
rnf ListTests' {Maybe Text
Text
arn :: Text
nextToken :: Maybe Text
$sel:arn:ListTests' :: ListTests -> Text
$sel:nextToken:ListTests' :: ListTests -> 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 ListTests where
  toHeaders :: ListTests -> 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.ListTests" ::
                          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 ListTests where
  toJSON :: ListTests -> Value
toJSON ListTests' {Maybe Text
Text
arn :: Text
nextToken :: Maybe Text
$sel:arn:ListTests' :: ListTests -> Text
$sel:nextToken:ListTests' :: ListTests -> 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 ListTests where
  toPath :: ListTests -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | Represents the result of a list tests request.
--
-- /See:/ 'newListTestsResponse' smart constructor.
data ListTestsResponse = ListTestsResponse'
  { -- | 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.
    ListTestsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Information about the tests.
    ListTestsResponse -> Maybe [Test]
tests :: Prelude.Maybe [Test],
    -- | The response's http status code.
    ListTestsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListTestsResponse -> ListTestsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTestsResponse -> ListTestsResponse -> Bool
$c/= :: ListTestsResponse -> ListTestsResponse -> Bool
== :: ListTestsResponse -> ListTestsResponse -> Bool
$c== :: ListTestsResponse -> ListTestsResponse -> Bool
Prelude.Eq, ReadPrec [ListTestsResponse]
ReadPrec ListTestsResponse
Int -> ReadS ListTestsResponse
ReadS [ListTestsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTestsResponse]
$creadListPrec :: ReadPrec [ListTestsResponse]
readPrec :: ReadPrec ListTestsResponse
$creadPrec :: ReadPrec ListTestsResponse
readList :: ReadS [ListTestsResponse]
$creadList :: ReadS [ListTestsResponse]
readsPrec :: Int -> ReadS ListTestsResponse
$creadsPrec :: Int -> ReadS ListTestsResponse
Prelude.Read, Int -> ListTestsResponse -> ShowS
[ListTestsResponse] -> ShowS
ListTestsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTestsResponse] -> ShowS
$cshowList :: [ListTestsResponse] -> ShowS
show :: ListTestsResponse -> String
$cshow :: ListTestsResponse -> String
showsPrec :: Int -> ListTestsResponse -> ShowS
$cshowsPrec :: Int -> ListTestsResponse -> ShowS
Prelude.Show, forall x. Rep ListTestsResponse x -> ListTestsResponse
forall x. ListTestsResponse -> Rep ListTestsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTestsResponse x -> ListTestsResponse
$cfrom :: forall x. ListTestsResponse -> Rep ListTestsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListTestsResponse' 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', 'listTestsResponse_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.
--
-- 'tests', 'listTestsResponse_tests' - Information about the tests.
--
-- 'httpStatus', 'listTestsResponse_httpStatus' - The response's http status code.
newListTestsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListTestsResponse
newListTestsResponse :: Int -> ListTestsResponse
newListTestsResponse Int
pHttpStatus_ =
  ListTestsResponse'
    { $sel:nextToken:ListTestsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:tests:ListTestsResponse' :: Maybe [Test]
tests = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListTestsResponse' :: 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.
listTestsResponse_nextToken :: Lens.Lens' ListTestsResponse (Prelude.Maybe Prelude.Text)
listTestsResponse_nextToken :: Lens' ListTestsResponse (Maybe Text)
listTestsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTestsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTestsResponse' :: ListTestsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTestsResponse
s@ListTestsResponse' {} Maybe Text
a -> ListTestsResponse
s {$sel:nextToken:ListTestsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListTestsResponse)

-- | Information about the tests.
listTestsResponse_tests :: Lens.Lens' ListTestsResponse (Prelude.Maybe [Test])
listTestsResponse_tests :: Lens' ListTestsResponse (Maybe [Test])
listTestsResponse_tests = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTestsResponse' {Maybe [Test]
tests :: Maybe [Test]
$sel:tests:ListTestsResponse' :: ListTestsResponse -> Maybe [Test]
tests} -> Maybe [Test]
tests) (\s :: ListTestsResponse
s@ListTestsResponse' {} Maybe [Test]
a -> ListTestsResponse
s {$sel:tests:ListTestsResponse' :: Maybe [Test]
tests = Maybe [Test]
a} :: ListTestsResponse) 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.
listTestsResponse_httpStatus :: Lens.Lens' ListTestsResponse Prelude.Int
listTestsResponse_httpStatus :: Lens' ListTestsResponse Int
listTestsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTestsResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListTestsResponse' :: ListTestsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListTestsResponse
s@ListTestsResponse' {} Int
a -> ListTestsResponse
s {$sel:httpStatus:ListTestsResponse' :: Int
httpStatus = Int
a} :: ListTestsResponse)

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