{-# 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.MediaTailor.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 that are associated with a MediaTailor channel assembly
-- resource.
--
-- This operation returns paginated results.
module Amazonka.MediaTailor.ListAlerts
  ( -- * Creating a Request
    ListAlerts (..),
    newListAlerts,

    -- * Request Lenses
    listAlerts_maxResults,
    listAlerts_nextToken,
    listAlerts_resourceArn,

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

    -- * Response Lenses
    listAlertsResponse_items,
    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.MediaTailor.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 maximum number of alerts that you want MediaTailor to return in
    -- response to the current request. If there are more than @MaxResults@
    -- alerts, use the value of @NextToken@ in the response to get the next
    -- page of results.
    ListAlerts -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | Pagination token returned by the list request when results exceed the
    -- maximum allowed. Use the token to fetch the next page of results.
    ListAlerts -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the resource.
    ListAlerts -> Text
resourceArn :: 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:
--
-- 'maxResults', 'listAlerts_maxResults' - The maximum number of alerts that you want MediaTailor to return in
-- response to the current request. If there are more than @MaxResults@
-- alerts, use the value of @NextToken@ in the response to get the next
-- page of results.
--
-- 'nextToken', 'listAlerts_nextToken' - Pagination token returned by the list request when results exceed the
-- maximum allowed. Use the token to fetch the next page of results.
--
-- 'resourceArn', 'listAlerts_resourceArn' - The Amazon Resource Name (ARN) of the resource.
newListAlerts ::
  -- | 'resourceArn'
  Prelude.Text ->
  ListAlerts
newListAlerts :: Text -> ListAlerts
newListAlerts Text
pResourceArn_ =
  ListAlerts'
    { $sel:maxResults:ListAlerts' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListAlerts' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:ListAlerts' :: Text
resourceArn = Text
pResourceArn_
    }

-- | The maximum number of alerts that you want MediaTailor to return in
-- response to the current request. If there are more than @MaxResults@
-- alerts, use the value of @NextToken@ in the response to get the next
-- page of results.
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)

-- | Pagination token returned by the list request when results exceed the
-- maximum allowed. Use the token to fetch the next page of results.
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)

-- | The Amazon Resource Name (ARN) of the resource.
listAlerts_resourceArn :: Lens.Lens' ListAlerts Prelude.Text
listAlerts_resourceArn :: Lens' ListAlerts Text
listAlerts_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAlerts' {Text
resourceArn :: Text
$sel:resourceArn:ListAlerts' :: ListAlerts -> Text
resourceArn} -> Text
resourceArn) (\s :: ListAlerts
s@ListAlerts' {} Text
a -> ListAlerts
s {$sel:resourceArn:ListAlerts' :: Text
resourceArn = Text
a} :: ListAlerts)

instance Core.AWSPager ListAlerts where
  page :: ListAlerts -> AWSResponse ListAlerts -> Maybe ListAlerts
page ListAlerts
rq AWSResponse ListAlerts
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListAlerts
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListAlertsResponse (Maybe Text)
listAlertsResponse_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 ListAlerts
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListAlertsResponse (Maybe [Alert])
listAlertsResponse_items
            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.$ ListAlerts
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListAlerts (Maybe Text)
listAlerts_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListAlerts
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListAlertsResponse (Maybe Text)
listAlertsResponse_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 ListAlerts where
  type AWSResponse ListAlerts = ListAlertsResponse
  request :: (Service -> Service) -> ListAlerts -> Request ListAlerts
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (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 [Alert] -> 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
"Items" 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
Text
resourceArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:resourceArn:ListAlerts' :: ListAlerts -> Text
$sel:nextToken:ListAlerts' :: ListAlerts -> Maybe Text
$sel:maxResults:ListAlerts' :: ListAlerts -> 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` Text
resourceArn

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

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.ToPath ListAlerts where
  toPath :: ListAlerts -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/alerts"

instance Data.ToQuery ListAlerts where
  toQuery :: ListAlerts -> QueryString
toQuery ListAlerts' {Maybe Natural
Maybe Text
Text
resourceArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:resourceArn:ListAlerts' :: ListAlerts -> Text
$sel:nextToken:ListAlerts' :: ListAlerts -> Maybe Text
$sel:maxResults:ListAlerts' :: ListAlerts -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"maxResults" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Natural
maxResults,
        ByteString
"nextToken" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
nextToken,
        ByteString
"resourceArn" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
resourceArn
      ]

-- | /See:/ 'newListAlertsResponse' smart constructor.
data ListAlertsResponse = ListAlertsResponse'
  { -- | A list of alerts that are associated with this resource.
    ListAlertsResponse -> Maybe [Alert]
items :: Prelude.Maybe [Alert],
    -- | Pagination token returned by the list request when results exceed the
    -- maximum allowed. Use the token to fetch the next page of results.
    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:
--
-- 'items', 'listAlertsResponse_items' - A list of alerts that are associated with this resource.
--
-- 'nextToken', 'listAlertsResponse_nextToken' - Pagination token returned by the list request when results exceed the
-- maximum allowed. Use the token to fetch the next page of results.
--
-- 'httpStatus', 'listAlertsResponse_httpStatus' - The response's http status code.
newListAlertsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListAlertsResponse
newListAlertsResponse :: Int -> ListAlertsResponse
newListAlertsResponse Int
pHttpStatus_ =
  ListAlertsResponse'
    { $sel:items:ListAlertsResponse' :: Maybe [Alert]
items = 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_
    }

-- | A list of alerts that are associated with this resource.
listAlertsResponse_items :: Lens.Lens' ListAlertsResponse (Prelude.Maybe [Alert])
listAlertsResponse_items :: Lens' ListAlertsResponse (Maybe [Alert])
listAlertsResponse_items = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListAlertsResponse' {Maybe [Alert]
items :: Maybe [Alert]
$sel:items:ListAlertsResponse' :: ListAlertsResponse -> Maybe [Alert]
items} -> Maybe [Alert]
items) (\s :: ListAlertsResponse
s@ListAlertsResponse' {} Maybe [Alert]
a -> ListAlertsResponse
s {$sel:items:ListAlertsResponse' :: Maybe [Alert]
items = Maybe [Alert]
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

-- | Pagination token returned by the list request when results exceed the
-- maximum allowed. Use the token to fetch the next page of results.
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 [Alert]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
items :: Maybe [Alert]
$sel:httpStatus:ListAlertsResponse' :: ListAlertsResponse -> Int
$sel:nextToken:ListAlertsResponse' :: ListAlertsResponse -> Maybe Text
$sel:items:ListAlertsResponse' :: ListAlertsResponse -> Maybe [Alert]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Alert]
items
      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