{-# 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.Route53RecoveryReadiness.ListRules
-- 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 all readiness rules, or lists the readiness rules for a specific
-- resource type.
--
-- This operation returns paginated results.
module Amazonka.Route53RecoveryReadiness.ListRules
  ( -- * Creating a Request
    ListRules (..),
    newListRules,

    -- * Request Lenses
    listRules_maxResults,
    listRules_nextToken,
    listRules_resourceType,

    -- * Destructuring the Response
    ListRulesResponse (..),
    newListRulesResponse,

    -- * Response Lenses
    listRulesResponse_nextToken,
    listRulesResponse_rules,
    listRulesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newListRules' smart constructor.
data ListRules = ListRules'
  { -- | The number of objects that you want to return with this call.
    ListRules -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The token that identifies which batch of results you want to see.
    ListRules -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The resource type that a readiness rule applies to.
    ListRules -> Maybe Text
resourceType :: Prelude.Maybe Prelude.Text
  }
  deriving (ListRules -> ListRules -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListRules -> ListRules -> Bool
$c/= :: ListRules -> ListRules -> Bool
== :: ListRules -> ListRules -> Bool
$c== :: ListRules -> ListRules -> Bool
Prelude.Eq, ReadPrec [ListRules]
ReadPrec ListRules
Int -> ReadS ListRules
ReadS [ListRules]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListRules]
$creadListPrec :: ReadPrec [ListRules]
readPrec :: ReadPrec ListRules
$creadPrec :: ReadPrec ListRules
readList :: ReadS [ListRules]
$creadList :: ReadS [ListRules]
readsPrec :: Int -> ReadS ListRules
$creadsPrec :: Int -> ReadS ListRules
Prelude.Read, Int -> ListRules -> ShowS
[ListRules] -> ShowS
ListRules -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListRules] -> ShowS
$cshowList :: [ListRules] -> ShowS
show :: ListRules -> String
$cshow :: ListRules -> String
showsPrec :: Int -> ListRules -> ShowS
$cshowsPrec :: Int -> ListRules -> ShowS
Prelude.Show, forall x. Rep ListRules x -> ListRules
forall x. ListRules -> Rep ListRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListRules x -> ListRules
$cfrom :: forall x. ListRules -> Rep ListRules x
Prelude.Generic)

-- |
-- Create a value of 'ListRules' 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', 'listRules_maxResults' - The number of objects that you want to return with this call.
--
-- 'nextToken', 'listRules_nextToken' - The token that identifies which batch of results you want to see.
--
-- 'resourceType', 'listRules_resourceType' - The resource type that a readiness rule applies to.
newListRules ::
  ListRules
newListRules :: ListRules
newListRules =
  ListRules'
    { $sel:maxResults:ListRules' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListRules' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceType:ListRules' :: Maybe Text
resourceType = forall a. Maybe a
Prelude.Nothing
    }

-- | The number of objects that you want to return with this call.
listRules_maxResults :: Lens.Lens' ListRules (Prelude.Maybe Prelude.Natural)
listRules_maxResults :: Lens' ListRules (Maybe Natural)
listRules_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRules' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListRules' :: ListRules -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListRules
s@ListRules' {} Maybe Natural
a -> ListRules
s {$sel:maxResults:ListRules' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListRules)

-- | The token that identifies which batch of results you want to see.
listRules_nextToken :: Lens.Lens' ListRules (Prelude.Maybe Prelude.Text)
listRules_nextToken :: Lens' ListRules (Maybe Text)
listRules_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRules' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListRules' :: ListRules -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListRules
s@ListRules' {} Maybe Text
a -> ListRules
s {$sel:nextToken:ListRules' :: Maybe Text
nextToken = Maybe Text
a} :: ListRules)

-- | The resource type that a readiness rule applies to.
listRules_resourceType :: Lens.Lens' ListRules (Prelude.Maybe Prelude.Text)
listRules_resourceType :: Lens' ListRules (Maybe Text)
listRules_resourceType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRules' {Maybe Text
resourceType :: Maybe Text
$sel:resourceType:ListRules' :: ListRules -> Maybe Text
resourceType} -> Maybe Text
resourceType) (\s :: ListRules
s@ListRules' {} Maybe Text
a -> ListRules
s {$sel:resourceType:ListRules' :: Maybe Text
resourceType = Maybe Text
a} :: ListRules)

instance Core.AWSPager ListRules where
  page :: ListRules -> AWSResponse ListRules -> Maybe ListRules
page ListRules
rq AWSResponse ListRules
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListRules
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRulesResponse (Maybe Text)
listRulesResponse_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 ListRules
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRulesResponse (Maybe [ListRulesOutput])
listRulesResponse_rules
            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.$ ListRules
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListRules (Maybe Text)
listRules_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListRules
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListRulesResponse (Maybe Text)
listRulesResponse_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 ListRules where
  type AWSResponse ListRules = ListRulesResponse
  request :: (Service -> Service) -> ListRules -> Request ListRules
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 ListRules
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListRules)))
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 [ListRulesOutput] -> Int -> ListRulesResponse
ListRulesResponse'
            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
"rules" 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 ListRules where
  hashWithSalt :: Int -> ListRules -> Int
hashWithSalt Int
_salt ListRules' {Maybe Natural
Maybe Text
resourceType :: Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:resourceType:ListRules' :: ListRules -> Maybe Text
$sel:nextToken:ListRules' :: ListRules -> Maybe Text
$sel:maxResults:ListRules' :: ListRules -> 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` Maybe Text
resourceType

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

instance Data.ToHeaders ListRules where
  toHeaders :: ListRules -> 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 ListRules where
  toPath :: ListRules -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/rules"

instance Data.ToQuery ListRules where
  toQuery :: ListRules -> QueryString
toQuery ListRules' {Maybe Natural
Maybe Text
resourceType :: Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:resourceType:ListRules' :: ListRules -> Maybe Text
$sel:nextToken:ListRules' :: ListRules -> Maybe Text
$sel:maxResults:ListRules' :: ListRules -> 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
"resourceType" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
resourceType
      ]

-- | /See:/ 'newListRulesResponse' smart constructor.
data ListRulesResponse = ListRulesResponse'
  { -- | The token that identifies which batch of results you want to see.
    ListRulesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A list of readiness rules for a specific resource type.
    ListRulesResponse -> Maybe [ListRulesOutput]
rules :: Prelude.Maybe [ListRulesOutput],
    -- | The response's http status code.
    ListRulesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListRulesResponse -> ListRulesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListRulesResponse -> ListRulesResponse -> Bool
$c/= :: ListRulesResponse -> ListRulesResponse -> Bool
== :: ListRulesResponse -> ListRulesResponse -> Bool
$c== :: ListRulesResponse -> ListRulesResponse -> Bool
Prelude.Eq, ReadPrec [ListRulesResponse]
ReadPrec ListRulesResponse
Int -> ReadS ListRulesResponse
ReadS [ListRulesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListRulesResponse]
$creadListPrec :: ReadPrec [ListRulesResponse]
readPrec :: ReadPrec ListRulesResponse
$creadPrec :: ReadPrec ListRulesResponse
readList :: ReadS [ListRulesResponse]
$creadList :: ReadS [ListRulesResponse]
readsPrec :: Int -> ReadS ListRulesResponse
$creadsPrec :: Int -> ReadS ListRulesResponse
Prelude.Read, Int -> ListRulesResponse -> ShowS
[ListRulesResponse] -> ShowS
ListRulesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListRulesResponse] -> ShowS
$cshowList :: [ListRulesResponse] -> ShowS
show :: ListRulesResponse -> String
$cshow :: ListRulesResponse -> String
showsPrec :: Int -> ListRulesResponse -> ShowS
$cshowsPrec :: Int -> ListRulesResponse -> ShowS
Prelude.Show, forall x. Rep ListRulesResponse x -> ListRulesResponse
forall x. ListRulesResponse -> Rep ListRulesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListRulesResponse x -> ListRulesResponse
$cfrom :: forall x. ListRulesResponse -> Rep ListRulesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListRulesResponse' 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', 'listRulesResponse_nextToken' - The token that identifies which batch of results you want to see.
--
-- 'rules', 'listRulesResponse_rules' - A list of readiness rules for a specific resource type.
--
-- 'httpStatus', 'listRulesResponse_httpStatus' - The response's http status code.
newListRulesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListRulesResponse
newListRulesResponse :: Int -> ListRulesResponse
newListRulesResponse Int
pHttpStatus_ =
  ListRulesResponse'
    { $sel:nextToken:ListRulesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:rules:ListRulesResponse' :: Maybe [ListRulesOutput]
rules = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListRulesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The token that identifies which batch of results you want to see.
listRulesResponse_nextToken :: Lens.Lens' ListRulesResponse (Prelude.Maybe Prelude.Text)
listRulesResponse_nextToken :: Lens' ListRulesResponse (Maybe Text)
listRulesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRulesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListRulesResponse' :: ListRulesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListRulesResponse
s@ListRulesResponse' {} Maybe Text
a -> ListRulesResponse
s {$sel:nextToken:ListRulesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListRulesResponse)

-- | A list of readiness rules for a specific resource type.
listRulesResponse_rules :: Lens.Lens' ListRulesResponse (Prelude.Maybe [ListRulesOutput])
listRulesResponse_rules :: Lens' ListRulesResponse (Maybe [ListRulesOutput])
listRulesResponse_rules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRulesResponse' {Maybe [ListRulesOutput]
rules :: Maybe [ListRulesOutput]
$sel:rules:ListRulesResponse' :: ListRulesResponse -> Maybe [ListRulesOutput]
rules} -> Maybe [ListRulesOutput]
rules) (\s :: ListRulesResponse
s@ListRulesResponse' {} Maybe [ListRulesOutput]
a -> ListRulesResponse
s {$sel:rules:ListRulesResponse' :: Maybe [ListRulesOutput]
rules = Maybe [ListRulesOutput]
a} :: ListRulesResponse) 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.
listRulesResponse_httpStatus :: Lens.Lens' ListRulesResponse Prelude.Int
listRulesResponse_httpStatus :: Lens' ListRulesResponse Int
listRulesResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListRulesResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListRulesResponse' :: ListRulesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListRulesResponse
s@ListRulesResponse' {} Int
a -> ListRulesResponse
s {$sel:httpStatus:ListRulesResponse' :: Int
httpStatus = Int
a} :: ListRulesResponse)

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