{-# 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.GetControl
-- 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 control from Audit Manager.
module Amazonka.AuditManager.GetControl
  ( -- * Creating a Request
    GetControl (..),
    newGetControl,

    -- * Request Lenses
    getControl_controlId,

    -- * Destructuring the Response
    GetControlResponse (..),
    newGetControlResponse,

    -- * Response Lenses
    getControlResponse_control,
    getControlResponse_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:/ 'newGetControl' smart constructor.
data GetControl = GetControl'
  { -- | The identifier for the control.
    GetControl -> Text
controlId :: Prelude.Text
  }
  deriving (GetControl -> GetControl -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetControl -> GetControl -> Bool
$c/= :: GetControl -> GetControl -> Bool
== :: GetControl -> GetControl -> Bool
$c== :: GetControl -> GetControl -> Bool
Prelude.Eq, ReadPrec [GetControl]
ReadPrec GetControl
Int -> ReadS GetControl
ReadS [GetControl]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetControl]
$creadListPrec :: ReadPrec [GetControl]
readPrec :: ReadPrec GetControl
$creadPrec :: ReadPrec GetControl
readList :: ReadS [GetControl]
$creadList :: ReadS [GetControl]
readsPrec :: Int -> ReadS GetControl
$creadsPrec :: Int -> ReadS GetControl
Prelude.Read, Int -> GetControl -> ShowS
[GetControl] -> ShowS
GetControl -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetControl] -> ShowS
$cshowList :: [GetControl] -> ShowS
show :: GetControl -> String
$cshow :: GetControl -> String
showsPrec :: Int -> GetControl -> ShowS
$cshowsPrec :: Int -> GetControl -> ShowS
Prelude.Show, forall x. Rep GetControl x -> GetControl
forall x. GetControl -> Rep GetControl x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetControl x -> GetControl
$cfrom :: forall x. GetControl -> Rep GetControl x
Prelude.Generic)

-- |
-- Create a value of 'GetControl' 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:
--
-- 'controlId', 'getControl_controlId' - The identifier for the control.
newGetControl ::
  -- | 'controlId'
  Prelude.Text ->
  GetControl
newGetControl :: Text -> GetControl
newGetControl Text
pControlId_ =
  GetControl' {$sel:controlId:GetControl' :: Text
controlId = Text
pControlId_}

-- | The identifier for the control.
getControl_controlId :: Lens.Lens' GetControl Prelude.Text
getControl_controlId :: Lens' GetControl Text
getControl_controlId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetControl' {Text
controlId :: Text
$sel:controlId:GetControl' :: GetControl -> Text
controlId} -> Text
controlId) (\s :: GetControl
s@GetControl' {} Text
a -> GetControl
s {$sel:controlId:GetControl' :: Text
controlId = Text
a} :: GetControl)

instance Core.AWSRequest GetControl where
  type AWSResponse GetControl = GetControlResponse
  request :: (Service -> Service) -> GetControl -> Request GetControl
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 GetControl
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetControl)))
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 Control -> Int -> GetControlResponse
GetControlResponse'
            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
"control")
            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 GetControl where
  hashWithSalt :: Int -> GetControl -> Int
hashWithSalt Int
_salt GetControl' {Text
controlId :: Text
$sel:controlId:GetControl' :: GetControl -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
controlId

instance Prelude.NFData GetControl where
  rnf :: GetControl -> ()
rnf GetControl' {Text
controlId :: Text
$sel:controlId:GetControl' :: GetControl -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
controlId

instance Data.ToHeaders GetControl where
  toHeaders :: GetControl -> 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 GetControl where
  toPath :: GetControl -> ByteString
toPath GetControl' {Text
controlId :: Text
$sel:controlId:GetControl' :: GetControl -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/controls/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
controlId]

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

-- | /See:/ 'newGetControlResponse' smart constructor.
data GetControlResponse = GetControlResponse'
  { -- | The name of the control that the @GetControl@ API returned.
    GetControlResponse -> Maybe Control
control :: Prelude.Maybe Control,
    -- | The response's http status code.
    GetControlResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetControlResponse -> GetControlResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetControlResponse -> GetControlResponse -> Bool
$c/= :: GetControlResponse -> GetControlResponse -> Bool
== :: GetControlResponse -> GetControlResponse -> Bool
$c== :: GetControlResponse -> GetControlResponse -> Bool
Prelude.Eq, ReadPrec [GetControlResponse]
ReadPrec GetControlResponse
Int -> ReadS GetControlResponse
ReadS [GetControlResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetControlResponse]
$creadListPrec :: ReadPrec [GetControlResponse]
readPrec :: ReadPrec GetControlResponse
$creadPrec :: ReadPrec GetControlResponse
readList :: ReadS [GetControlResponse]
$creadList :: ReadS [GetControlResponse]
readsPrec :: Int -> ReadS GetControlResponse
$creadsPrec :: Int -> ReadS GetControlResponse
Prelude.Read, Int -> GetControlResponse -> ShowS
[GetControlResponse] -> ShowS
GetControlResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetControlResponse] -> ShowS
$cshowList :: [GetControlResponse] -> ShowS
show :: GetControlResponse -> String
$cshow :: GetControlResponse -> String
showsPrec :: Int -> GetControlResponse -> ShowS
$cshowsPrec :: Int -> GetControlResponse -> ShowS
Prelude.Show, forall x. Rep GetControlResponse x -> GetControlResponse
forall x. GetControlResponse -> Rep GetControlResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetControlResponse x -> GetControlResponse
$cfrom :: forall x. GetControlResponse -> Rep GetControlResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetControlResponse' 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:
--
-- 'control', 'getControlResponse_control' - The name of the control that the @GetControl@ API returned.
--
-- 'httpStatus', 'getControlResponse_httpStatus' - The response's http status code.
newGetControlResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetControlResponse
newGetControlResponse :: Int -> GetControlResponse
newGetControlResponse Int
pHttpStatus_ =
  GetControlResponse'
    { $sel:control:GetControlResponse' :: Maybe Control
control = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetControlResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The name of the control that the @GetControl@ API returned.
getControlResponse_control :: Lens.Lens' GetControlResponse (Prelude.Maybe Control)
getControlResponse_control :: Lens' GetControlResponse (Maybe Control)
getControlResponse_control = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetControlResponse' {Maybe Control
control :: Maybe Control
$sel:control:GetControlResponse' :: GetControlResponse -> Maybe Control
control} -> Maybe Control
control) (\s :: GetControlResponse
s@GetControlResponse' {} Maybe Control
a -> GetControlResponse
s {$sel:control:GetControlResponse' :: Maybe Control
control = Maybe Control
a} :: GetControlResponse)

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

instance Prelude.NFData GetControlResponse where
  rnf :: GetControlResponse -> ()
rnf GetControlResponse' {Int
Maybe Control
httpStatus :: Int
control :: Maybe Control
$sel:httpStatus:GetControlResponse' :: GetControlResponse -> Int
$sel:control:GetControlResponse' :: GetControlResponse -> Maybe Control
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Control
control
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus