{-# 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.Backup.ListLegalHolds
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- This action returns metadata about active and previous legal holds.
--
-- This operation returns paginated results.
module Amazonka.Backup.ListLegalHolds
  ( -- * Creating a Request
    ListLegalHolds (..),
    newListLegalHolds,

    -- * Request Lenses
    listLegalHolds_maxResults,
    listLegalHolds_nextToken,

    -- * Destructuring the Response
    ListLegalHoldsResponse (..),
    newListLegalHoldsResponse,

    -- * Response Lenses
    listLegalHoldsResponse_legalHolds,
    listLegalHoldsResponse_nextToken,
    listLegalHoldsResponse_httpStatus,
  )
where

import Amazonka.Backup.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:/ 'newListLegalHolds' smart constructor.
data ListLegalHolds = ListLegalHolds'
  { -- | The maximum number of resource list items to be returned.
    ListLegalHolds -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The next item following a partial list of returned resources. For
    -- example, if a request is made to return @maxResults@ number of
    -- resources, @NextToken@ allows you to return more items in your list
    -- starting at the location pointed to by the next token.
    ListLegalHolds -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListLegalHolds -> ListLegalHolds -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListLegalHolds -> ListLegalHolds -> Bool
$c/= :: ListLegalHolds -> ListLegalHolds -> Bool
== :: ListLegalHolds -> ListLegalHolds -> Bool
$c== :: ListLegalHolds -> ListLegalHolds -> Bool
Prelude.Eq, ReadPrec [ListLegalHolds]
ReadPrec ListLegalHolds
Int -> ReadS ListLegalHolds
ReadS [ListLegalHolds]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListLegalHolds]
$creadListPrec :: ReadPrec [ListLegalHolds]
readPrec :: ReadPrec ListLegalHolds
$creadPrec :: ReadPrec ListLegalHolds
readList :: ReadS [ListLegalHolds]
$creadList :: ReadS [ListLegalHolds]
readsPrec :: Int -> ReadS ListLegalHolds
$creadsPrec :: Int -> ReadS ListLegalHolds
Prelude.Read, Int -> ListLegalHolds -> ShowS
[ListLegalHolds] -> ShowS
ListLegalHolds -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListLegalHolds] -> ShowS
$cshowList :: [ListLegalHolds] -> ShowS
show :: ListLegalHolds -> String
$cshow :: ListLegalHolds -> String
showsPrec :: Int -> ListLegalHolds -> ShowS
$cshowsPrec :: Int -> ListLegalHolds -> ShowS
Prelude.Show, forall x. Rep ListLegalHolds x -> ListLegalHolds
forall x. ListLegalHolds -> Rep ListLegalHolds x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListLegalHolds x -> ListLegalHolds
$cfrom :: forall x. ListLegalHolds -> Rep ListLegalHolds x
Prelude.Generic)

-- |
-- Create a value of 'ListLegalHolds' 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', 'listLegalHolds_maxResults' - The maximum number of resource list items to be returned.
--
-- 'nextToken', 'listLegalHolds_nextToken' - The next item following a partial list of returned resources. For
-- example, if a request is made to return @maxResults@ number of
-- resources, @NextToken@ allows you to return more items in your list
-- starting at the location pointed to by the next token.
newListLegalHolds ::
  ListLegalHolds
newListLegalHolds :: ListLegalHolds
newListLegalHolds =
  ListLegalHolds'
    { $sel:maxResults:ListLegalHolds' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListLegalHolds' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of resource list items to be returned.
listLegalHolds_maxResults :: Lens.Lens' ListLegalHolds (Prelude.Maybe Prelude.Natural)
listLegalHolds_maxResults :: Lens' ListLegalHolds (Maybe Natural)
listLegalHolds_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListLegalHolds' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListLegalHolds' :: ListLegalHolds -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListLegalHolds
s@ListLegalHolds' {} Maybe Natural
a -> ListLegalHolds
s {$sel:maxResults:ListLegalHolds' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListLegalHolds)

-- | The next item following a partial list of returned resources. For
-- example, if a request is made to return @maxResults@ number of
-- resources, @NextToken@ allows you to return more items in your list
-- starting at the location pointed to by the next token.
listLegalHolds_nextToken :: Lens.Lens' ListLegalHolds (Prelude.Maybe Prelude.Text)
listLegalHolds_nextToken :: Lens' ListLegalHolds (Maybe Text)
listLegalHolds_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListLegalHolds' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListLegalHolds' :: ListLegalHolds -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListLegalHolds
s@ListLegalHolds' {} Maybe Text
a -> ListLegalHolds
s {$sel:nextToken:ListLegalHolds' :: Maybe Text
nextToken = Maybe Text
a} :: ListLegalHolds)

instance Core.AWSPager ListLegalHolds where
  page :: ListLegalHolds
-> AWSResponse ListLegalHolds -> Maybe ListLegalHolds
page ListLegalHolds
rq AWSResponse ListLegalHolds
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListLegalHolds
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListLegalHoldsResponse (Maybe Text)
listLegalHoldsResponse_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 ListLegalHolds
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListLegalHoldsResponse (Maybe [LegalHold])
listLegalHoldsResponse_legalHolds
            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.$ ListLegalHolds
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListLegalHolds (Maybe Text)
listLegalHolds_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListLegalHolds
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListLegalHoldsResponse (Maybe Text)
listLegalHoldsResponse_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 ListLegalHolds where
  type
    AWSResponse ListLegalHolds =
      ListLegalHoldsResponse
  request :: (Service -> Service) -> ListLegalHolds -> Request ListLegalHolds
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 ListLegalHolds
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListLegalHolds)))
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 [LegalHold] -> Maybe Text -> Int -> ListLegalHoldsResponse
ListLegalHoldsResponse'
            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
"LegalHolds" 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 ListLegalHolds where
  hashWithSalt :: Int -> ListLegalHolds -> Int
hashWithSalt Int
_salt ListLegalHolds' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListLegalHolds' :: ListLegalHolds -> Maybe Text
$sel:maxResults:ListLegalHolds' :: ListLegalHolds -> 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 ListLegalHolds where
  rnf :: ListLegalHolds -> ()
rnf ListLegalHolds' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListLegalHolds' :: ListLegalHolds -> Maybe Text
$sel:maxResults:ListLegalHolds' :: ListLegalHolds -> 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 ListLegalHolds where
  toHeaders :: ListLegalHolds -> 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 ListLegalHolds where
  toPath :: ListLegalHolds -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/legal-holds/"

instance Data.ToQuery ListLegalHolds where
  toQuery :: ListLegalHolds -> QueryString
toQuery ListLegalHolds' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:nextToken:ListLegalHolds' :: ListLegalHolds -> Maybe Text
$sel:maxResults:ListLegalHolds' :: ListLegalHolds -> 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
      ]

-- | /See:/ 'newListLegalHoldsResponse' smart constructor.
data ListLegalHoldsResponse = ListLegalHoldsResponse'
  { -- | This is an array of returned legal holds, both active and previous.
    ListLegalHoldsResponse -> Maybe [LegalHold]
legalHolds :: Prelude.Maybe [LegalHold],
    -- | The next item following a partial list of returned resources. For
    -- example, if a request is made to return @maxResults@ number of
    -- resources, @NextToken@ allows you to return more items in your list
    -- starting at the location pointed to by the next token.
    ListLegalHoldsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListLegalHoldsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListLegalHoldsResponse -> ListLegalHoldsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListLegalHoldsResponse -> ListLegalHoldsResponse -> Bool
$c/= :: ListLegalHoldsResponse -> ListLegalHoldsResponse -> Bool
== :: ListLegalHoldsResponse -> ListLegalHoldsResponse -> Bool
$c== :: ListLegalHoldsResponse -> ListLegalHoldsResponse -> Bool
Prelude.Eq, ReadPrec [ListLegalHoldsResponse]
ReadPrec ListLegalHoldsResponse
Int -> ReadS ListLegalHoldsResponse
ReadS [ListLegalHoldsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListLegalHoldsResponse]
$creadListPrec :: ReadPrec [ListLegalHoldsResponse]
readPrec :: ReadPrec ListLegalHoldsResponse
$creadPrec :: ReadPrec ListLegalHoldsResponse
readList :: ReadS [ListLegalHoldsResponse]
$creadList :: ReadS [ListLegalHoldsResponse]
readsPrec :: Int -> ReadS ListLegalHoldsResponse
$creadsPrec :: Int -> ReadS ListLegalHoldsResponse
Prelude.Read, Int -> ListLegalHoldsResponse -> ShowS
[ListLegalHoldsResponse] -> ShowS
ListLegalHoldsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListLegalHoldsResponse] -> ShowS
$cshowList :: [ListLegalHoldsResponse] -> ShowS
show :: ListLegalHoldsResponse -> String
$cshow :: ListLegalHoldsResponse -> String
showsPrec :: Int -> ListLegalHoldsResponse -> ShowS
$cshowsPrec :: Int -> ListLegalHoldsResponse -> ShowS
Prelude.Show, forall x. Rep ListLegalHoldsResponse x -> ListLegalHoldsResponse
forall x. ListLegalHoldsResponse -> Rep ListLegalHoldsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListLegalHoldsResponse x -> ListLegalHoldsResponse
$cfrom :: forall x. ListLegalHoldsResponse -> Rep ListLegalHoldsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListLegalHoldsResponse' 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:
--
-- 'legalHolds', 'listLegalHoldsResponse_legalHolds' - This is an array of returned legal holds, both active and previous.
--
-- 'nextToken', 'listLegalHoldsResponse_nextToken' - The next item following a partial list of returned resources. For
-- example, if a request is made to return @maxResults@ number of
-- resources, @NextToken@ allows you to return more items in your list
-- starting at the location pointed to by the next token.
--
-- 'httpStatus', 'listLegalHoldsResponse_httpStatus' - The response's http status code.
newListLegalHoldsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListLegalHoldsResponse
newListLegalHoldsResponse :: Int -> ListLegalHoldsResponse
newListLegalHoldsResponse Int
pHttpStatus_ =
  ListLegalHoldsResponse'
    { $sel:legalHolds:ListLegalHoldsResponse' :: Maybe [LegalHold]
legalHolds =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListLegalHoldsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListLegalHoldsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | This is an array of returned legal holds, both active and previous.
listLegalHoldsResponse_legalHolds :: Lens.Lens' ListLegalHoldsResponse (Prelude.Maybe [LegalHold])
listLegalHoldsResponse_legalHolds :: Lens' ListLegalHoldsResponse (Maybe [LegalHold])
listLegalHoldsResponse_legalHolds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListLegalHoldsResponse' {Maybe [LegalHold]
legalHolds :: Maybe [LegalHold]
$sel:legalHolds:ListLegalHoldsResponse' :: ListLegalHoldsResponse -> Maybe [LegalHold]
legalHolds} -> Maybe [LegalHold]
legalHolds) (\s :: ListLegalHoldsResponse
s@ListLegalHoldsResponse' {} Maybe [LegalHold]
a -> ListLegalHoldsResponse
s {$sel:legalHolds:ListLegalHoldsResponse' :: Maybe [LegalHold]
legalHolds = Maybe [LegalHold]
a} :: ListLegalHoldsResponse) 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 next item following a partial list of returned resources. For
-- example, if a request is made to return @maxResults@ number of
-- resources, @NextToken@ allows you to return more items in your list
-- starting at the location pointed to by the next token.
listLegalHoldsResponse_nextToken :: Lens.Lens' ListLegalHoldsResponse (Prelude.Maybe Prelude.Text)
listLegalHoldsResponse_nextToken :: Lens' ListLegalHoldsResponse (Maybe Text)
listLegalHoldsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListLegalHoldsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListLegalHoldsResponse' :: ListLegalHoldsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListLegalHoldsResponse
s@ListLegalHoldsResponse' {} Maybe Text
a -> ListLegalHoldsResponse
s {$sel:nextToken:ListLegalHoldsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListLegalHoldsResponse)

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

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