{-# 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.ListAlerts
-- 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 alerts attached to a detector.
--
-- 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.ListAlerts
  ( -- * Creating a Request
    ListAlerts (..),
    newListAlerts,

    -- * Request Lenses
    listAlerts_anomalyDetectorArn,
    listAlerts_maxResults,
    listAlerts_nextToken,

    -- * Destructuring the Response
    ListAlertsResponse (..),
    newListAlertsResponse,

    -- * Response Lenses
    listAlertsResponse_alertSummaryList,
    listAlertsResponse_nextToken,
    listAlertsResponse_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:/ 'newListAlerts' smart constructor.
data ListAlerts = ListAlerts'
  { -- | The ARN of the alert\'s detector.
    ListAlerts -> Maybe Text
anomalyDetectorArn :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of results that will be displayed by the request.
    ListAlerts -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | If the result of the previous request is 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.
    ListAlerts -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListAlerts -> ListAlerts -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListAlerts -> ListAlerts -> Bool
$c/= :: ListAlerts -> ListAlerts -> Bool
== :: ListAlerts -> ListAlerts -> Bool
$c== :: ListAlerts -> ListAlerts -> Bool
Prelude.Eq, ReadPrec [ListAlerts]
ReadPrec ListAlerts
Int -> ReadS ListAlerts
ReadS [ListAlerts]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListAlerts]
$creadListPrec :: ReadPrec [ListAlerts]
readPrec :: ReadPrec ListAlerts
$creadPrec :: ReadPrec ListAlerts
readList :: ReadS [ListAlerts]
$creadList :: ReadS [ListAlerts]
readsPrec :: Int -> ReadS ListAlerts
$creadsPrec :: Int -> ReadS ListAlerts
Prelude.Read, Int -> ListAlerts -> ShowS
[ListAlerts] -> ShowS
ListAlerts -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListAlerts] -> ShowS
$cshowList :: [ListAlerts] -> ShowS
show :: ListAlerts -> String
$cshow :: ListAlerts -> String
showsPrec :: Int -> ListAlerts -> ShowS
$cshowsPrec :: Int -> ListAlerts -> ShowS
Prelude.Show, forall x. Rep ListAlerts x -> ListAlerts
forall x. ListAlerts -> Rep ListAlerts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListAlerts x -> ListAlerts
$cfrom :: forall x. ListAlerts -> Rep ListAlerts x
Prelude.Generic)

-- |
-- Create a value of 'ListAlerts' 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:
--
-- 'anomalyDetectorArn', 'listAlerts_anomalyDetectorArn' - The ARN of the alert\'s detector.
--
-- 'maxResults', 'listAlerts_maxResults' - The maximum number of results that will be displayed by the request.
--
-- 'nextToken', 'listAlerts_nextToken' - If the result of the previous request is 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.
newListAlerts ::
  ListAlerts
newListAlerts :: ListAlerts
newListAlerts =
  ListAlerts'
    { $sel:anomalyDetectorArn:ListAlerts' :: Maybe Text
anomalyDetectorArn = forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListAlerts' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListAlerts' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The ARN of the alert\'s detector.
listAlerts_anomalyDetectorArn :: Lens.Lens' ListAlerts (Prelude.Maybe Prelude.Text)
listAlerts_anomalyDetectorArn :: Lens' ListAlerts (Maybe Text)
listAlerts_anomalyDetectorArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAlerts' {Maybe Text
anomalyDetectorArn :: Maybe Text
$sel:anomalyDetectorArn:ListAlerts' :: ListAlerts -> Maybe Text
anomalyDetectorArn} -> Maybe Text
anomalyDetectorArn) (\s :: ListAlerts
s@ListAlerts' {} Maybe Text
a -> ListAlerts
s {$sel:anomalyDetectorArn:ListAlerts' :: Maybe Text
anomalyDetectorArn = Maybe Text
a} :: ListAlerts)

-- | The maximum number of results that will be displayed by the request.
listAlerts_maxResults :: Lens.Lens' ListAlerts (Prelude.Maybe Prelude.Natural)
listAlerts_maxResults :: Lens' ListAlerts (Maybe Natural)
listAlerts_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAlerts' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListAlerts' :: ListAlerts -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListAlerts
s@ListAlerts' {} Maybe Natural
a -> ListAlerts
s {$sel:maxResults:ListAlerts' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListAlerts)

-- | If the result of the previous request is 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.
listAlerts_nextToken :: Lens.Lens' ListAlerts (Prelude.Maybe Prelude.Text)
listAlerts_nextToken :: Lens' ListAlerts (Maybe Text)
listAlerts_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAlerts' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListAlerts' :: ListAlerts -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListAlerts
s@ListAlerts' {} Maybe Text
a -> ListAlerts
s {$sel:nextToken:ListAlerts' :: Maybe Text
nextToken = Maybe Text
a} :: ListAlerts)

instance Core.AWSRequest ListAlerts where
  type AWSResponse ListAlerts = ListAlertsResponse
  request :: (Service -> Service) -> ListAlerts -> Request ListAlerts
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 ListAlerts
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListAlerts)))
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 [AlertSummary] -> Maybe Text -> Int -> ListAlertsResponse
ListAlertsResponse'
            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
"AlertSummaryList"
                            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 ListAlerts where
  hashWithSalt :: Int -> ListAlerts -> Int
hashWithSalt Int
_salt ListAlerts' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
anomalyDetectorArn :: Maybe Text
$sel:nextToken:ListAlerts' :: ListAlerts -> Maybe Text
$sel:maxResults:ListAlerts' :: ListAlerts -> Maybe Natural
$sel:anomalyDetectorArn:ListAlerts' :: ListAlerts -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
anomalyDetectorArn
      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 ListAlerts where
  rnf :: ListAlerts -> ()
rnf ListAlerts' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
anomalyDetectorArn :: Maybe Text
$sel:nextToken:ListAlerts' :: ListAlerts -> Maybe Text
$sel:maxResults:ListAlerts' :: ListAlerts -> Maybe Natural
$sel:anomalyDetectorArn:ListAlerts' :: ListAlerts -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
anomalyDetectorArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 ListAlerts where
  toHeaders :: ListAlerts -> 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 ListAlerts where
  toJSON :: ListAlerts -> Value
toJSON ListAlerts' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
anomalyDetectorArn :: Maybe Text
$sel:nextToken:ListAlerts' :: ListAlerts -> Maybe Text
$sel:maxResults:ListAlerts' :: ListAlerts -> Maybe Natural
$sel:anomalyDetectorArn:ListAlerts' :: ListAlerts -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AnomalyDetectorArn" 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
anomalyDetectorArn,
            (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 ListAlerts where
  toPath :: ListAlerts -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/ListAlerts"

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

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

-- |
-- Create a value of 'ListAlertsResponse' 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:
--
-- 'alertSummaryList', 'listAlertsResponse_alertSummaryList' - Contains information about an alert.
--
-- 'nextToken', 'listAlertsResponse_nextToken' - If the response is truncated, the service returns this token. To
-- retrieve the next set of results, use this token in the next request.
--
-- 'httpStatus', 'listAlertsResponse_httpStatus' - The response's http status code.
newListAlertsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListAlertsResponse
newListAlertsResponse :: Int -> ListAlertsResponse
newListAlertsResponse Int
pHttpStatus_ =
  ListAlertsResponse'
    { $sel:alertSummaryList:ListAlertsResponse' :: Maybe [AlertSummary]
alertSummaryList =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListAlertsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListAlertsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Contains information about an alert.
listAlertsResponse_alertSummaryList :: Lens.Lens' ListAlertsResponse (Prelude.Maybe [AlertSummary])
listAlertsResponse_alertSummaryList :: Lens' ListAlertsResponse (Maybe [AlertSummary])
listAlertsResponse_alertSummaryList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAlertsResponse' {Maybe [AlertSummary]
alertSummaryList :: Maybe [AlertSummary]
$sel:alertSummaryList:ListAlertsResponse' :: ListAlertsResponse -> Maybe [AlertSummary]
alertSummaryList} -> Maybe [AlertSummary]
alertSummaryList) (\s :: ListAlertsResponse
s@ListAlertsResponse' {} Maybe [AlertSummary]
a -> ListAlertsResponse
s {$sel:alertSummaryList:ListAlertsResponse' :: Maybe [AlertSummary]
alertSummaryList = Maybe [AlertSummary]
a} :: ListAlertsResponse) 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 this token in the next request.
listAlertsResponse_nextToken :: Lens.Lens' ListAlertsResponse (Prelude.Maybe Prelude.Text)
listAlertsResponse_nextToken :: Lens' ListAlertsResponse (Maybe Text)
listAlertsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAlertsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListAlertsResponse' :: ListAlertsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListAlertsResponse
s@ListAlertsResponse' {} Maybe Text
a -> ListAlertsResponse
s {$sel:nextToken:ListAlertsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListAlertsResponse)

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

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