{-# 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.Braket.SearchDevices
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Searches for devices using the specified filters.
--
-- This operation returns paginated results.
module Amazonka.Braket.SearchDevices
  ( -- * Creating a Request
    SearchDevices (..),
    newSearchDevices,

    -- * Request Lenses
    searchDevices_maxResults,
    searchDevices_nextToken,
    searchDevices_filters,

    -- * Destructuring the Response
    SearchDevicesResponse (..),
    newSearchDevicesResponse,

    -- * Response Lenses
    searchDevicesResponse_nextToken,
    searchDevicesResponse_httpStatus,
    searchDevicesResponse_devices,
  )
where

import Amazonka.Braket.Types
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

-- | /See:/ 'newSearchDevices' smart constructor.
data SearchDevices = SearchDevices'
  { -- | The maximum number of results to return in the response.
    SearchDevices -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | A token used for pagination of results returned in the response. Use the
    -- token returned from the previous request continue results where the
    -- previous request ended.
    SearchDevices -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The filter values to use to search for a device.
    SearchDevices -> [SearchDevicesFilter]
filters :: [SearchDevicesFilter]
  }
  deriving (SearchDevices -> SearchDevices -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SearchDevices -> SearchDevices -> Bool
$c/= :: SearchDevices -> SearchDevices -> Bool
== :: SearchDevices -> SearchDevices -> Bool
$c== :: SearchDevices -> SearchDevices -> Bool
Prelude.Eq, ReadPrec [SearchDevices]
ReadPrec SearchDevices
Int -> ReadS SearchDevices
ReadS [SearchDevices]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SearchDevices]
$creadListPrec :: ReadPrec [SearchDevices]
readPrec :: ReadPrec SearchDevices
$creadPrec :: ReadPrec SearchDevices
readList :: ReadS [SearchDevices]
$creadList :: ReadS [SearchDevices]
readsPrec :: Int -> ReadS SearchDevices
$creadsPrec :: Int -> ReadS SearchDevices
Prelude.Read, Int -> SearchDevices -> ShowS
[SearchDevices] -> ShowS
SearchDevices -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SearchDevices] -> ShowS
$cshowList :: [SearchDevices] -> ShowS
show :: SearchDevices -> String
$cshow :: SearchDevices -> String
showsPrec :: Int -> SearchDevices -> ShowS
$cshowsPrec :: Int -> SearchDevices -> ShowS
Prelude.Show, forall x. Rep SearchDevices x -> SearchDevices
forall x. SearchDevices -> Rep SearchDevices x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SearchDevices x -> SearchDevices
$cfrom :: forall x. SearchDevices -> Rep SearchDevices x
Prelude.Generic)

-- |
-- Create a value of 'SearchDevices' 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', 'searchDevices_maxResults' - The maximum number of results to return in the response.
--
-- 'nextToken', 'searchDevices_nextToken' - A token used for pagination of results returned in the response. Use the
-- token returned from the previous request continue results where the
-- previous request ended.
--
-- 'filters', 'searchDevices_filters' - The filter values to use to search for a device.
newSearchDevices ::
  SearchDevices
newSearchDevices :: SearchDevices
newSearchDevices =
  SearchDevices'
    { $sel:maxResults:SearchDevices' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:SearchDevices' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:filters:SearchDevices' :: [SearchDevicesFilter]
filters = forall a. Monoid a => a
Prelude.mempty
    }

-- | The maximum number of results to return in the response.
searchDevices_maxResults :: Lens.Lens' SearchDevices (Prelude.Maybe Prelude.Natural)
searchDevices_maxResults :: Lens' SearchDevices (Maybe Natural)
searchDevices_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchDevices' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:SearchDevices' :: SearchDevices -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: SearchDevices
s@SearchDevices' {} Maybe Natural
a -> SearchDevices
s {$sel:maxResults:SearchDevices' :: Maybe Natural
maxResults = Maybe Natural
a} :: SearchDevices)

-- | A token used for pagination of results returned in the response. Use the
-- token returned from the previous request continue results where the
-- previous request ended.
searchDevices_nextToken :: Lens.Lens' SearchDevices (Prelude.Maybe Prelude.Text)
searchDevices_nextToken :: Lens' SearchDevices (Maybe Text)
searchDevices_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchDevices' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:SearchDevices' :: SearchDevices -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: SearchDevices
s@SearchDevices' {} Maybe Text
a -> SearchDevices
s {$sel:nextToken:SearchDevices' :: Maybe Text
nextToken = Maybe Text
a} :: SearchDevices)

-- | The filter values to use to search for a device.
searchDevices_filters :: Lens.Lens' SearchDevices [SearchDevicesFilter]
searchDevices_filters :: Lens' SearchDevices [SearchDevicesFilter]
searchDevices_filters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchDevices' {[SearchDevicesFilter]
filters :: [SearchDevicesFilter]
$sel:filters:SearchDevices' :: SearchDevices -> [SearchDevicesFilter]
filters} -> [SearchDevicesFilter]
filters) (\s :: SearchDevices
s@SearchDevices' {} [SearchDevicesFilter]
a -> SearchDevices
s {$sel:filters:SearchDevices' :: [SearchDevicesFilter]
filters = [SearchDevicesFilter]
a} :: SearchDevices) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSPager SearchDevices where
  page :: SearchDevices -> AWSResponse SearchDevices -> Maybe SearchDevices
page SearchDevices
rq AWSResponse SearchDevices
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse SearchDevices
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' SearchDevicesResponse (Maybe Text)
searchDevicesResponse_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 SearchDevices
rs forall s a. s -> Getting a s a -> a
Lens.^. Lens' SearchDevicesResponse [DeviceSummary]
searchDevicesResponse_devices) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ SearchDevices
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' SearchDevices (Maybe Text)
searchDevices_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse SearchDevices
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' SearchDevicesResponse (Maybe Text)
searchDevicesResponse_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 SearchDevices where
  type
    AWSResponse SearchDevices =
      SearchDevicesResponse
  request :: (Service -> Service) -> SearchDevices -> Request SearchDevices
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 SearchDevices
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse SearchDevices)))
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 -> Int -> [DeviceSummary] -> SearchDevicesResponse
SearchDevicesResponse'
            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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            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
"devices" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable SearchDevices where
  hashWithSalt :: Int -> SearchDevices -> Int
hashWithSalt Int
_salt SearchDevices' {[SearchDevicesFilter]
Maybe Natural
Maybe Text
filters :: [SearchDevicesFilter]
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:filters:SearchDevices' :: SearchDevices -> [SearchDevicesFilter]
$sel:nextToken:SearchDevices' :: SearchDevices -> Maybe Text
$sel:maxResults:SearchDevices' :: SearchDevices -> 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` [SearchDevicesFilter]
filters

instance Prelude.NFData SearchDevices where
  rnf :: SearchDevices -> ()
rnf SearchDevices' {[SearchDevicesFilter]
Maybe Natural
Maybe Text
filters :: [SearchDevicesFilter]
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:filters:SearchDevices' :: SearchDevices -> [SearchDevicesFilter]
$sel:nextToken:SearchDevices' :: SearchDevices -> Maybe Text
$sel:maxResults:SearchDevices' :: SearchDevices -> 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 [SearchDevicesFilter]
filters

instance Data.ToHeaders SearchDevices where
  toHeaders :: SearchDevices -> 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.ToJSON SearchDevices where
  toJSON :: SearchDevices -> Value
toJSON SearchDevices' {[SearchDevicesFilter]
Maybe Natural
Maybe Text
filters :: [SearchDevicesFilter]
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:filters:SearchDevices' :: SearchDevices -> [SearchDevicesFilter]
$sel:nextToken:SearchDevices' :: SearchDevices -> Maybe Text
$sel:maxResults:SearchDevices' :: SearchDevices -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"maxResults" 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 Natural
maxResults,
            (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
"filters" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [SearchDevicesFilter]
filters)
          ]
      )

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

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

-- | /See:/ 'newSearchDevicesResponse' smart constructor.
data SearchDevicesResponse = SearchDevicesResponse'
  { -- | A token used for pagination of results, or null if there are no
    -- additional results. Use the token value in a subsequent request to
    -- continue results where the previous request ended.
    SearchDevicesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    SearchDevicesResponse -> Int
httpStatus :: Prelude.Int,
    -- | An array of @DeviceSummary@ objects for devices that match the specified
    -- filter values.
    SearchDevicesResponse -> [DeviceSummary]
devices :: [DeviceSummary]
  }
  deriving (SearchDevicesResponse -> SearchDevicesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SearchDevicesResponse -> SearchDevicesResponse -> Bool
$c/= :: SearchDevicesResponse -> SearchDevicesResponse -> Bool
== :: SearchDevicesResponse -> SearchDevicesResponse -> Bool
$c== :: SearchDevicesResponse -> SearchDevicesResponse -> Bool
Prelude.Eq, ReadPrec [SearchDevicesResponse]
ReadPrec SearchDevicesResponse
Int -> ReadS SearchDevicesResponse
ReadS [SearchDevicesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SearchDevicesResponse]
$creadListPrec :: ReadPrec [SearchDevicesResponse]
readPrec :: ReadPrec SearchDevicesResponse
$creadPrec :: ReadPrec SearchDevicesResponse
readList :: ReadS [SearchDevicesResponse]
$creadList :: ReadS [SearchDevicesResponse]
readsPrec :: Int -> ReadS SearchDevicesResponse
$creadsPrec :: Int -> ReadS SearchDevicesResponse
Prelude.Read, Int -> SearchDevicesResponse -> ShowS
[SearchDevicesResponse] -> ShowS
SearchDevicesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SearchDevicesResponse] -> ShowS
$cshowList :: [SearchDevicesResponse] -> ShowS
show :: SearchDevicesResponse -> String
$cshow :: SearchDevicesResponse -> String
showsPrec :: Int -> SearchDevicesResponse -> ShowS
$cshowsPrec :: Int -> SearchDevicesResponse -> ShowS
Prelude.Show, forall x. Rep SearchDevicesResponse x -> SearchDevicesResponse
forall x. SearchDevicesResponse -> Rep SearchDevicesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SearchDevicesResponse x -> SearchDevicesResponse
$cfrom :: forall x. SearchDevicesResponse -> Rep SearchDevicesResponse x
Prelude.Generic)

-- |
-- Create a value of 'SearchDevicesResponse' 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', 'searchDevicesResponse_nextToken' - A token used for pagination of results, or null if there are no
-- additional results. Use the token value in a subsequent request to
-- continue results where the previous request ended.
--
-- 'httpStatus', 'searchDevicesResponse_httpStatus' - The response's http status code.
--
-- 'devices', 'searchDevicesResponse_devices' - An array of @DeviceSummary@ objects for devices that match the specified
-- filter values.
newSearchDevicesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SearchDevicesResponse
newSearchDevicesResponse :: Int -> SearchDevicesResponse
newSearchDevicesResponse Int
pHttpStatus_ =
  SearchDevicesResponse'
    { $sel:nextToken:SearchDevicesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SearchDevicesResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:devices:SearchDevicesResponse' :: [DeviceSummary]
devices = forall a. Monoid a => a
Prelude.mempty
    }

-- | A token used for pagination of results, or null if there are no
-- additional results. Use the token value in a subsequent request to
-- continue results where the previous request ended.
searchDevicesResponse_nextToken :: Lens.Lens' SearchDevicesResponse (Prelude.Maybe Prelude.Text)
searchDevicesResponse_nextToken :: Lens' SearchDevicesResponse (Maybe Text)
searchDevicesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchDevicesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:SearchDevicesResponse' :: SearchDevicesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: SearchDevicesResponse
s@SearchDevicesResponse' {} Maybe Text
a -> SearchDevicesResponse
s {$sel:nextToken:SearchDevicesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: SearchDevicesResponse)

-- | The response's http status code.
searchDevicesResponse_httpStatus :: Lens.Lens' SearchDevicesResponse Prelude.Int
searchDevicesResponse_httpStatus :: Lens' SearchDevicesResponse Int
searchDevicesResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchDevicesResponse' {Int
httpStatus :: Int
$sel:httpStatus:SearchDevicesResponse' :: SearchDevicesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: SearchDevicesResponse
s@SearchDevicesResponse' {} Int
a -> SearchDevicesResponse
s {$sel:httpStatus:SearchDevicesResponse' :: Int
httpStatus = Int
a} :: SearchDevicesResponse)

-- | An array of @DeviceSummary@ objects for devices that match the specified
-- filter values.
searchDevicesResponse_devices :: Lens.Lens' SearchDevicesResponse [DeviceSummary]
searchDevicesResponse_devices :: Lens' SearchDevicesResponse [DeviceSummary]
searchDevicesResponse_devices = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchDevicesResponse' {[DeviceSummary]
devices :: [DeviceSummary]
$sel:devices:SearchDevicesResponse' :: SearchDevicesResponse -> [DeviceSummary]
devices} -> [DeviceSummary]
devices) (\s :: SearchDevicesResponse
s@SearchDevicesResponse' {} [DeviceSummary]
a -> SearchDevicesResponse
s {$sel:devices:SearchDevicesResponse' :: [DeviceSummary]
devices = [DeviceSummary]
a} :: SearchDevicesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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