{-# 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.LookoutMetrics.ListAnomalyDetectors
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Lists the detectors in the current AWS Region.
--
-- Amazon Lookout for Metrics API actions are eventually consistent. If you
-- do a read operation on a resource immediately after creating or
-- modifying it, use retries to allow time for the write operation to
-- complete.
module Amazonka.LookoutMetrics.ListAnomalyDetectors
  ( -- * Creating a Request
    ListAnomalyDetectors (..),
    newListAnomalyDetectors,

    -- * Request Lenses
    listAnomalyDetectors_maxResults,
    listAnomalyDetectors_nextToken,

    -- * Destructuring the Response
    ListAnomalyDetectorsResponse (..),
    newListAnomalyDetectorsResponse,

    -- * Response Lenses
    listAnomalyDetectorsResponse_anomalyDetectorSummaryList,
    listAnomalyDetectorsResponse_nextToken,
    listAnomalyDetectorsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListAnomalyDetectors' smart constructor.
data ListAnomalyDetectors = ListAnomalyDetectors'
  { -- | The maximum number of results to return.
    ListAnomalyDetectors -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | If the result of the previous request was truncated, the response
    -- includes a @NextToken@. To retrieve the next set of results, use the
    -- token in the next request. Tokens expire after 24 hours.
    ListAnomalyDetectors -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListAnomalyDetectors -> ListAnomalyDetectors -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListAnomalyDetectors -> ListAnomalyDetectors -> Bool
$c/= :: ListAnomalyDetectors -> ListAnomalyDetectors -> Bool
== :: ListAnomalyDetectors -> ListAnomalyDetectors -> Bool
$c== :: ListAnomalyDetectors -> ListAnomalyDetectors -> Bool
Prelude.Eq, ReadPrec [ListAnomalyDetectors]
ReadPrec ListAnomalyDetectors
Int -> ReadS ListAnomalyDetectors
ReadS [ListAnomalyDetectors]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListAnomalyDetectors]
$creadListPrec :: ReadPrec [ListAnomalyDetectors]
readPrec :: ReadPrec ListAnomalyDetectors
$creadPrec :: ReadPrec ListAnomalyDetectors
readList :: ReadS [ListAnomalyDetectors]
$creadList :: ReadS [ListAnomalyDetectors]
readsPrec :: Int -> ReadS ListAnomalyDetectors
$creadsPrec :: Int -> ReadS ListAnomalyDetectors
Prelude.Read, Int -> ListAnomalyDetectors -> ShowS
[ListAnomalyDetectors] -> ShowS
ListAnomalyDetectors -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListAnomalyDetectors] -> ShowS
$cshowList :: [ListAnomalyDetectors] -> ShowS
show :: ListAnomalyDetectors -> String
$cshow :: ListAnomalyDetectors -> String
showsPrec :: Int -> ListAnomalyDetectors -> ShowS
$cshowsPrec :: Int -> ListAnomalyDetectors -> ShowS
Prelude.Show, forall x. Rep ListAnomalyDetectors x -> ListAnomalyDetectors
forall x. ListAnomalyDetectors -> Rep ListAnomalyDetectors x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListAnomalyDetectors x -> ListAnomalyDetectors
$cfrom :: forall x. ListAnomalyDetectors -> Rep ListAnomalyDetectors x
Prelude.Generic)

-- |
-- Create a value of 'ListAnomalyDetectors' 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', 'listAnomalyDetectors_maxResults' - The maximum number of results to return.
--
-- 'nextToken', 'listAnomalyDetectors_nextToken' - If the result of the previous request was truncated, the response
-- includes a @NextToken@. To retrieve the next set of results, use the
-- token in the next request. Tokens expire after 24 hours.
newListAnomalyDetectors ::
  ListAnomalyDetectors
newListAnomalyDetectors :: ListAnomalyDetectors
newListAnomalyDetectors =
  ListAnomalyDetectors'
    { $sel:maxResults:ListAnomalyDetectors' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListAnomalyDetectors' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

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

-- | If the result of the previous request was truncated, the response
-- includes a @NextToken@. To retrieve the next set of results, use the
-- token in the next request. Tokens expire after 24 hours.
listAnomalyDetectors_nextToken :: Lens.Lens' ListAnomalyDetectors (Prelude.Maybe Prelude.Text)
listAnomalyDetectors_nextToken :: Lens' ListAnomalyDetectors (Maybe Text)
listAnomalyDetectors_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAnomalyDetectors' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListAnomalyDetectors' :: ListAnomalyDetectors -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListAnomalyDetectors
s@ListAnomalyDetectors' {} Maybe Text
a -> ListAnomalyDetectors
s {$sel:nextToken:ListAnomalyDetectors' :: Maybe Text
nextToken = Maybe Text
a} :: ListAnomalyDetectors)

instance Core.AWSRequest ListAnomalyDetectors where
  type
    AWSResponse ListAnomalyDetectors =
      ListAnomalyDetectorsResponse
  request :: (Service -> Service)
-> ListAnomalyDetectors -> Request ListAnomalyDetectors
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 ListAnomalyDetectors
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ListAnomalyDetectors)))
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 [AnomalyDetectorSummary]
-> Maybe Text -> Int -> ListAnomalyDetectorsResponse
ListAnomalyDetectorsResponse'
            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
"AnomalyDetectorSummaryList"
                            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.<*> (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))
      )

instance Prelude.Hashable ListAnomalyDetectors where
  hashWithSalt :: Int -> ListAnomalyDetectors -> Int
hashWithSalt Int
_salt ListAnomalyDetectors' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListAnomalyDetectors' :: ListAnomalyDetectors -> Maybe Text
$sel:maxResults:ListAnomalyDetectors' :: ListAnomalyDetectors -> 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

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

instance Data.ToHeaders ListAnomalyDetectors where
  toHeaders :: ListAnomalyDetectors -> 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 ListAnomalyDetectors where
  toJSON :: ListAnomalyDetectors -> Value
toJSON ListAnomalyDetectors' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListAnomalyDetectors' :: ListAnomalyDetectors -> Maybe Text
$sel:maxResults:ListAnomalyDetectors' :: ListAnomalyDetectors -> 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
          ]
      )

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

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

-- | /See:/ 'newListAnomalyDetectorsResponse' smart constructor.
data ListAnomalyDetectorsResponse = ListAnomalyDetectorsResponse'
  { -- | A list of anomaly detectors in the account in the current region.
    ListAnomalyDetectorsResponse -> Maybe [AnomalyDetectorSummary]
anomalyDetectorSummaryList :: Prelude.Maybe [AnomalyDetectorSummary],
    -- | If the response is truncated, the service returns this token. To
    -- retrieve the next set of results, use the token in the next request.
    ListAnomalyDetectorsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListAnomalyDetectorsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListAnomalyDetectorsResponse
-> ListAnomalyDetectorsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListAnomalyDetectorsResponse
-> ListAnomalyDetectorsResponse -> Bool
$c/= :: ListAnomalyDetectorsResponse
-> ListAnomalyDetectorsResponse -> Bool
== :: ListAnomalyDetectorsResponse
-> ListAnomalyDetectorsResponse -> Bool
$c== :: ListAnomalyDetectorsResponse
-> ListAnomalyDetectorsResponse -> Bool
Prelude.Eq, ReadPrec [ListAnomalyDetectorsResponse]
ReadPrec ListAnomalyDetectorsResponse
Int -> ReadS ListAnomalyDetectorsResponse
ReadS [ListAnomalyDetectorsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListAnomalyDetectorsResponse]
$creadListPrec :: ReadPrec [ListAnomalyDetectorsResponse]
readPrec :: ReadPrec ListAnomalyDetectorsResponse
$creadPrec :: ReadPrec ListAnomalyDetectorsResponse
readList :: ReadS [ListAnomalyDetectorsResponse]
$creadList :: ReadS [ListAnomalyDetectorsResponse]
readsPrec :: Int -> ReadS ListAnomalyDetectorsResponse
$creadsPrec :: Int -> ReadS ListAnomalyDetectorsResponse
Prelude.Read, Int -> ListAnomalyDetectorsResponse -> ShowS
[ListAnomalyDetectorsResponse] -> ShowS
ListAnomalyDetectorsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListAnomalyDetectorsResponse] -> ShowS
$cshowList :: [ListAnomalyDetectorsResponse] -> ShowS
show :: ListAnomalyDetectorsResponse -> String
$cshow :: ListAnomalyDetectorsResponse -> String
showsPrec :: Int -> ListAnomalyDetectorsResponse -> ShowS
$cshowsPrec :: Int -> ListAnomalyDetectorsResponse -> ShowS
Prelude.Show, forall x.
Rep ListAnomalyDetectorsResponse x -> ListAnomalyDetectorsResponse
forall x.
ListAnomalyDetectorsResponse -> Rep ListAnomalyDetectorsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListAnomalyDetectorsResponse x -> ListAnomalyDetectorsResponse
$cfrom :: forall x.
ListAnomalyDetectorsResponse -> Rep ListAnomalyDetectorsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListAnomalyDetectorsResponse' 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:
--
-- 'anomalyDetectorSummaryList', 'listAnomalyDetectorsResponse_anomalyDetectorSummaryList' - A list of anomaly detectors in the account in the current region.
--
-- 'nextToken', 'listAnomalyDetectorsResponse_nextToken' - If the response is truncated, the service returns this token. To
-- retrieve the next set of results, use the token in the next request.
--
-- 'httpStatus', 'listAnomalyDetectorsResponse_httpStatus' - The response's http status code.
newListAnomalyDetectorsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListAnomalyDetectorsResponse
newListAnomalyDetectorsResponse :: Int -> ListAnomalyDetectorsResponse
newListAnomalyDetectorsResponse Int
pHttpStatus_ =
  ListAnomalyDetectorsResponse'
    { $sel:anomalyDetectorSummaryList:ListAnomalyDetectorsResponse' :: Maybe [AnomalyDetectorSummary]
anomalyDetectorSummaryList =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListAnomalyDetectorsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListAnomalyDetectorsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of anomaly detectors in the account in the current region.
listAnomalyDetectorsResponse_anomalyDetectorSummaryList :: Lens.Lens' ListAnomalyDetectorsResponse (Prelude.Maybe [AnomalyDetectorSummary])
listAnomalyDetectorsResponse_anomalyDetectorSummaryList :: Lens' ListAnomalyDetectorsResponse (Maybe [AnomalyDetectorSummary])
listAnomalyDetectorsResponse_anomalyDetectorSummaryList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAnomalyDetectorsResponse' {Maybe [AnomalyDetectorSummary]
anomalyDetectorSummaryList :: Maybe [AnomalyDetectorSummary]
$sel:anomalyDetectorSummaryList:ListAnomalyDetectorsResponse' :: ListAnomalyDetectorsResponse -> Maybe [AnomalyDetectorSummary]
anomalyDetectorSummaryList} -> Maybe [AnomalyDetectorSummary]
anomalyDetectorSummaryList) (\s :: ListAnomalyDetectorsResponse
s@ListAnomalyDetectorsResponse' {} Maybe [AnomalyDetectorSummary]
a -> ListAnomalyDetectorsResponse
s {$sel:anomalyDetectorSummaryList:ListAnomalyDetectorsResponse' :: Maybe [AnomalyDetectorSummary]
anomalyDetectorSummaryList = Maybe [AnomalyDetectorSummary]
a} :: ListAnomalyDetectorsResponse) 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

-- | If the response is truncated, the service returns this token. To
-- retrieve the next set of results, use the token in the next request.
listAnomalyDetectorsResponse_nextToken :: Lens.Lens' ListAnomalyDetectorsResponse (Prelude.Maybe Prelude.Text)
listAnomalyDetectorsResponse_nextToken :: Lens' ListAnomalyDetectorsResponse (Maybe Text)
listAnomalyDetectorsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAnomalyDetectorsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListAnomalyDetectorsResponse' :: ListAnomalyDetectorsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListAnomalyDetectorsResponse
s@ListAnomalyDetectorsResponse' {} Maybe Text
a -> ListAnomalyDetectorsResponse
s {$sel:nextToken:ListAnomalyDetectorsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListAnomalyDetectorsResponse)

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

instance Prelude.NFData ListAnomalyDetectorsResponse where
  rnf :: ListAnomalyDetectorsResponse -> ()
rnf ListAnomalyDetectorsResponse' {Int
Maybe [AnomalyDetectorSummary]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
anomalyDetectorSummaryList :: Maybe [AnomalyDetectorSummary]
$sel:httpStatus:ListAnomalyDetectorsResponse' :: ListAnomalyDetectorsResponse -> Int
$sel:nextToken:ListAnomalyDetectorsResponse' :: ListAnomalyDetectorsResponse -> Maybe Text
$sel:anomalyDetectorSummaryList:ListAnomalyDetectorsResponse' :: ListAnomalyDetectorsResponse -> Maybe [AnomalyDetectorSummary]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [AnomalyDetectorSummary]
anomalyDetectorSummaryList
      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 Int
httpStatus