{-# 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.AuditManager.ListControls
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns a list of controls from Audit Manager.
module Amazonka.AuditManager.ListControls
  ( -- * Creating a Request
    ListControls (..),
    newListControls,

    -- * Request Lenses
    listControls_maxResults,
    listControls_nextToken,
    listControls_controlType,

    -- * Destructuring the Response
    ListControlsResponse (..),
    newListControlsResponse,

    -- * Response Lenses
    listControlsResponse_controlMetadataList,
    listControlsResponse_nextToken,
    listControlsResponse_httpStatus,
  )
where

import Amazonka.AuditManager.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:/ 'newListControls' smart constructor.
data ListControls = ListControls'
  { -- | Represents the maximum number of results on a page or for an API request
    -- call.
    ListControls -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The pagination token that\'s used to fetch the next set of results.
    ListControls -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The type of control, such as a standard control or a custom control.
    ListControls -> ControlType
controlType :: ControlType
  }
  deriving (ListControls -> ListControls -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListControls -> ListControls -> Bool
$c/= :: ListControls -> ListControls -> Bool
== :: ListControls -> ListControls -> Bool
$c== :: ListControls -> ListControls -> Bool
Prelude.Eq, ReadPrec [ListControls]
ReadPrec ListControls
Int -> ReadS ListControls
ReadS [ListControls]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListControls]
$creadListPrec :: ReadPrec [ListControls]
readPrec :: ReadPrec ListControls
$creadPrec :: ReadPrec ListControls
readList :: ReadS [ListControls]
$creadList :: ReadS [ListControls]
readsPrec :: Int -> ReadS ListControls
$creadsPrec :: Int -> ReadS ListControls
Prelude.Read, Int -> ListControls -> ShowS
[ListControls] -> ShowS
ListControls -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListControls] -> ShowS
$cshowList :: [ListControls] -> ShowS
show :: ListControls -> String
$cshow :: ListControls -> String
showsPrec :: Int -> ListControls -> ShowS
$cshowsPrec :: Int -> ListControls -> ShowS
Prelude.Show, forall x. Rep ListControls x -> ListControls
forall x. ListControls -> Rep ListControls x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListControls x -> ListControls
$cfrom :: forall x. ListControls -> Rep ListControls x
Prelude.Generic)

-- |
-- Create a value of 'ListControls' 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', 'listControls_maxResults' - Represents the maximum number of results on a page or for an API request
-- call.
--
-- 'nextToken', 'listControls_nextToken' - The pagination token that\'s used to fetch the next set of results.
--
-- 'controlType', 'listControls_controlType' - The type of control, such as a standard control or a custom control.
newListControls ::
  -- | 'controlType'
  ControlType ->
  ListControls
newListControls :: ControlType -> ListControls
newListControls ControlType
pControlType_ =
  ListControls'
    { $sel:maxResults:ListControls' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListControls' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:controlType:ListControls' :: ControlType
controlType = ControlType
pControlType_
    }

-- | Represents the maximum number of results on a page or for an API request
-- call.
listControls_maxResults :: Lens.Lens' ListControls (Prelude.Maybe Prelude.Natural)
listControls_maxResults :: Lens' ListControls (Maybe Natural)
listControls_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListControls' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListControls' :: ListControls -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListControls
s@ListControls' {} Maybe Natural
a -> ListControls
s {$sel:maxResults:ListControls' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListControls)

-- | The pagination token that\'s used to fetch the next set of results.
listControls_nextToken :: Lens.Lens' ListControls (Prelude.Maybe Prelude.Text)
listControls_nextToken :: Lens' ListControls (Maybe Text)
listControls_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListControls' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListControls' :: ListControls -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListControls
s@ListControls' {} Maybe Text
a -> ListControls
s {$sel:nextToken:ListControls' :: Maybe Text
nextToken = Maybe Text
a} :: ListControls)

-- | The type of control, such as a standard control or a custom control.
listControls_controlType :: Lens.Lens' ListControls ControlType
listControls_controlType :: Lens' ListControls ControlType
listControls_controlType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListControls' {ControlType
controlType :: ControlType
$sel:controlType:ListControls' :: ListControls -> ControlType
controlType} -> ControlType
controlType) (\s :: ListControls
s@ListControls' {} ControlType
a -> ListControls
s {$sel:controlType:ListControls' :: ControlType
controlType = ControlType
a} :: ListControls)

instance Core.AWSRequest ListControls where
  type AWSResponse ListControls = ListControlsResponse
  request :: (Service -> Service) -> ListControls -> Request ListControls
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 ListControls
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListControls)))
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 [ControlMetadata]
-> Maybe Text -> Int -> ListControlsResponse
ListControlsResponse'
            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
"controlMetadataList"
                            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 ListControls where
  hashWithSalt :: Int -> ListControls -> Int
hashWithSalt Int
_salt ListControls' {Maybe Natural
Maybe Text
ControlType
controlType :: ControlType
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:controlType:ListControls' :: ListControls -> ControlType
$sel:nextToken:ListControls' :: ListControls -> Maybe Text
$sel:maxResults:ListControls' :: ListControls -> 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` ControlType
controlType

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

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

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

-- | /See:/ 'newListControlsResponse' smart constructor.
data ListControlsResponse = ListControlsResponse'
  { -- | The list of control metadata objects that the @ListControls@ API
    -- returned.
    ListControlsResponse -> Maybe [ControlMetadata]
controlMetadataList :: Prelude.Maybe [ControlMetadata],
    -- | The pagination token that\'s used to fetch the next set of results.
    ListControlsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListControlsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListControlsResponse -> ListControlsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListControlsResponse -> ListControlsResponse -> Bool
$c/= :: ListControlsResponse -> ListControlsResponse -> Bool
== :: ListControlsResponse -> ListControlsResponse -> Bool
$c== :: ListControlsResponse -> ListControlsResponse -> Bool
Prelude.Eq, ReadPrec [ListControlsResponse]
ReadPrec ListControlsResponse
Int -> ReadS ListControlsResponse
ReadS [ListControlsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListControlsResponse]
$creadListPrec :: ReadPrec [ListControlsResponse]
readPrec :: ReadPrec ListControlsResponse
$creadPrec :: ReadPrec ListControlsResponse
readList :: ReadS [ListControlsResponse]
$creadList :: ReadS [ListControlsResponse]
readsPrec :: Int -> ReadS ListControlsResponse
$creadsPrec :: Int -> ReadS ListControlsResponse
Prelude.Read, Int -> ListControlsResponse -> ShowS
[ListControlsResponse] -> ShowS
ListControlsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListControlsResponse] -> ShowS
$cshowList :: [ListControlsResponse] -> ShowS
show :: ListControlsResponse -> String
$cshow :: ListControlsResponse -> String
showsPrec :: Int -> ListControlsResponse -> ShowS
$cshowsPrec :: Int -> ListControlsResponse -> ShowS
Prelude.Show, forall x. Rep ListControlsResponse x -> ListControlsResponse
forall x. ListControlsResponse -> Rep ListControlsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListControlsResponse x -> ListControlsResponse
$cfrom :: forall x. ListControlsResponse -> Rep ListControlsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListControlsResponse' 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:
--
-- 'controlMetadataList', 'listControlsResponse_controlMetadataList' - The list of control metadata objects that the @ListControls@ API
-- returned.
--
-- 'nextToken', 'listControlsResponse_nextToken' - The pagination token that\'s used to fetch the next set of results.
--
-- 'httpStatus', 'listControlsResponse_httpStatus' - The response's http status code.
newListControlsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListControlsResponse
newListControlsResponse :: Int -> ListControlsResponse
newListControlsResponse Int
pHttpStatus_ =
  ListControlsResponse'
    { $sel:controlMetadataList:ListControlsResponse' :: Maybe [ControlMetadata]
controlMetadataList =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListControlsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListControlsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of control metadata objects that the @ListControls@ API
-- returned.
listControlsResponse_controlMetadataList :: Lens.Lens' ListControlsResponse (Prelude.Maybe [ControlMetadata])
listControlsResponse_controlMetadataList :: Lens' ListControlsResponse (Maybe [ControlMetadata])
listControlsResponse_controlMetadataList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListControlsResponse' {Maybe [ControlMetadata]
controlMetadataList :: Maybe [ControlMetadata]
$sel:controlMetadataList:ListControlsResponse' :: ListControlsResponse -> Maybe [ControlMetadata]
controlMetadataList} -> Maybe [ControlMetadata]
controlMetadataList) (\s :: ListControlsResponse
s@ListControlsResponse' {} Maybe [ControlMetadata]
a -> ListControlsResponse
s {$sel:controlMetadataList:ListControlsResponse' :: Maybe [ControlMetadata]
controlMetadataList = Maybe [ControlMetadata]
a} :: ListControlsResponse) 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 pagination token that\'s used to fetch the next set of results.
listControlsResponse_nextToken :: Lens.Lens' ListControlsResponse (Prelude.Maybe Prelude.Text)
listControlsResponse_nextToken :: Lens' ListControlsResponse (Maybe Text)
listControlsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListControlsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListControlsResponse' :: ListControlsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListControlsResponse
s@ListControlsResponse' {} Maybe Text
a -> ListControlsResponse
s {$sel:nextToken:ListControlsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListControlsResponse)

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

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