{-# 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.RegisterAccount
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Enables Audit Manager for the specified Amazon Web Services account.
module Amazonka.AuditManager.RegisterAccount
  ( -- * Creating a Request
    RegisterAccount (..),
    newRegisterAccount,

    -- * Request Lenses
    registerAccount_kmsKey,
    registerAccount_delegatedAdminAccount,

    -- * Destructuring the Response
    RegisterAccountResponse (..),
    newRegisterAccountResponse,

    -- * Response Lenses
    registerAccountResponse_status,
    registerAccountResponse_httpStatus,
  )
where

import Amazonka.AuditManager.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRegisterAccount' smart constructor.
data RegisterAccount = RegisterAccount'
  { -- | The KMS key details.
    RegisterAccount -> Maybe Text
kmsKey :: Prelude.Maybe Prelude.Text,
    -- | The delegated administrator account for Audit Manager.
    RegisterAccount -> Maybe Text
delegatedAdminAccount :: Prelude.Maybe Prelude.Text
  }
  deriving (RegisterAccount -> RegisterAccount -> Bool
(RegisterAccount -> RegisterAccount -> Bool)
-> (RegisterAccount -> RegisterAccount -> Bool)
-> Eq RegisterAccount
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterAccount -> RegisterAccount -> Bool
$c/= :: RegisterAccount -> RegisterAccount -> Bool
== :: RegisterAccount -> RegisterAccount -> Bool
$c== :: RegisterAccount -> RegisterAccount -> Bool
Prelude.Eq, ReadPrec [RegisterAccount]
ReadPrec RegisterAccount
Int -> ReadS RegisterAccount
ReadS [RegisterAccount]
(Int -> ReadS RegisterAccount)
-> ReadS [RegisterAccount]
-> ReadPrec RegisterAccount
-> ReadPrec [RegisterAccount]
-> Read RegisterAccount
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterAccount]
$creadListPrec :: ReadPrec [RegisterAccount]
readPrec :: ReadPrec RegisterAccount
$creadPrec :: ReadPrec RegisterAccount
readList :: ReadS [RegisterAccount]
$creadList :: ReadS [RegisterAccount]
readsPrec :: Int -> ReadS RegisterAccount
$creadsPrec :: Int -> ReadS RegisterAccount
Prelude.Read, Int -> RegisterAccount -> ShowS
[RegisterAccount] -> ShowS
RegisterAccount -> String
(Int -> RegisterAccount -> ShowS)
-> (RegisterAccount -> String)
-> ([RegisterAccount] -> ShowS)
-> Show RegisterAccount
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterAccount] -> ShowS
$cshowList :: [RegisterAccount] -> ShowS
show :: RegisterAccount -> String
$cshow :: RegisterAccount -> String
showsPrec :: Int -> RegisterAccount -> ShowS
$cshowsPrec :: Int -> RegisterAccount -> ShowS
Prelude.Show, (forall x. RegisterAccount -> Rep RegisterAccount x)
-> (forall x. Rep RegisterAccount x -> RegisterAccount)
-> Generic RegisterAccount
forall x. Rep RegisterAccount x -> RegisterAccount
forall x. RegisterAccount -> Rep RegisterAccount x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterAccount x -> RegisterAccount
$cfrom :: forall x. RegisterAccount -> Rep RegisterAccount x
Prelude.Generic)

-- |
-- Create a value of 'RegisterAccount' 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:
--
-- 'kmsKey', 'registerAccount_kmsKey' - The KMS key details.
--
-- 'delegatedAdminAccount', 'registerAccount_delegatedAdminAccount' - The delegated administrator account for Audit Manager.
newRegisterAccount ::
  RegisterAccount
newRegisterAccount :: RegisterAccount
newRegisterAccount =
  RegisterAccount' :: Maybe Text -> Maybe Text -> RegisterAccount
RegisterAccount'
    { $sel:kmsKey:RegisterAccount' :: Maybe Text
kmsKey = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:delegatedAdminAccount:RegisterAccount' :: Maybe Text
delegatedAdminAccount = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The KMS key details.
registerAccount_kmsKey :: Lens.Lens' RegisterAccount (Prelude.Maybe Prelude.Text)
registerAccount_kmsKey :: (Maybe Text -> f (Maybe Text))
-> RegisterAccount -> f RegisterAccount
registerAccount_kmsKey = (RegisterAccount -> Maybe Text)
-> (RegisterAccount -> Maybe Text -> RegisterAccount)
-> Lens RegisterAccount RegisterAccount (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterAccount' {Maybe Text
kmsKey :: Maybe Text
$sel:kmsKey:RegisterAccount' :: RegisterAccount -> Maybe Text
kmsKey} -> Maybe Text
kmsKey) (\s :: RegisterAccount
s@RegisterAccount' {} Maybe Text
a -> RegisterAccount
s {$sel:kmsKey:RegisterAccount' :: Maybe Text
kmsKey = Maybe Text
a} :: RegisterAccount)

-- | The delegated administrator account for Audit Manager.
registerAccount_delegatedAdminAccount :: Lens.Lens' RegisterAccount (Prelude.Maybe Prelude.Text)
registerAccount_delegatedAdminAccount :: (Maybe Text -> f (Maybe Text))
-> RegisterAccount -> f RegisterAccount
registerAccount_delegatedAdminAccount = (RegisterAccount -> Maybe Text)
-> (RegisterAccount -> Maybe Text -> RegisterAccount)
-> Lens RegisterAccount RegisterAccount (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterAccount' {Maybe Text
delegatedAdminAccount :: Maybe Text
$sel:delegatedAdminAccount:RegisterAccount' :: RegisterAccount -> Maybe Text
delegatedAdminAccount} -> Maybe Text
delegatedAdminAccount) (\s :: RegisterAccount
s@RegisterAccount' {} Maybe Text
a -> RegisterAccount
s {$sel:delegatedAdminAccount:RegisterAccount' :: Maybe Text
delegatedAdminAccount = Maybe Text
a} :: RegisterAccount)

instance Core.AWSRequest RegisterAccount where
  type
    AWSResponse RegisterAccount =
      RegisterAccountResponse
  request :: RegisterAccount -> Request RegisterAccount
request = Service -> RegisterAccount -> Request RegisterAccount
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RegisterAccount
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterAccount)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse RegisterAccount))
-> Logger
-> Service
-> Proxy RegisterAccount
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterAccount)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe AccountStatus -> Int -> RegisterAccountResponse
RegisterAccountResponse'
            (Maybe AccountStatus -> Int -> RegisterAccountResponse)
-> Either String (Maybe AccountStatus)
-> Either String (Int -> RegisterAccountResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe AccountStatus)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"status")
            Either String (Int -> RegisterAccountResponse)
-> Either String Int -> Either String RegisterAccountResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable RegisterAccount

instance Prelude.NFData RegisterAccount

instance Core.ToHeaders RegisterAccount where
  toHeaders :: RegisterAccount -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RegisterAccount -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON RegisterAccount where
  toJSON :: RegisterAccount -> Value
toJSON RegisterAccount' {Maybe Text
delegatedAdminAccount :: Maybe Text
kmsKey :: Maybe Text
$sel:delegatedAdminAccount:RegisterAccount' :: RegisterAccount -> Maybe Text
$sel:kmsKey:RegisterAccount' :: RegisterAccount -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"kmsKey" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
kmsKey,
            (Text
"delegatedAdminAccount" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
delegatedAdminAccount
          ]
      )

instance Core.ToPath RegisterAccount where
  toPath :: RegisterAccount -> ByteString
toPath = ByteString -> RegisterAccount -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/account/registerAccount"

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

-- | /See:/ 'newRegisterAccountResponse' smart constructor.
data RegisterAccountResponse = RegisterAccountResponse'
  { -- | The status of the account registration request.
    RegisterAccountResponse -> Maybe AccountStatus
status :: Prelude.Maybe AccountStatus,
    -- | The response's http status code.
    RegisterAccountResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RegisterAccountResponse -> RegisterAccountResponse -> Bool
(RegisterAccountResponse -> RegisterAccountResponse -> Bool)
-> (RegisterAccountResponse -> RegisterAccountResponse -> Bool)
-> Eq RegisterAccountResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterAccountResponse -> RegisterAccountResponse -> Bool
$c/= :: RegisterAccountResponse -> RegisterAccountResponse -> Bool
== :: RegisterAccountResponse -> RegisterAccountResponse -> Bool
$c== :: RegisterAccountResponse -> RegisterAccountResponse -> Bool
Prelude.Eq, ReadPrec [RegisterAccountResponse]
ReadPrec RegisterAccountResponse
Int -> ReadS RegisterAccountResponse
ReadS [RegisterAccountResponse]
(Int -> ReadS RegisterAccountResponse)
-> ReadS [RegisterAccountResponse]
-> ReadPrec RegisterAccountResponse
-> ReadPrec [RegisterAccountResponse]
-> Read RegisterAccountResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterAccountResponse]
$creadListPrec :: ReadPrec [RegisterAccountResponse]
readPrec :: ReadPrec RegisterAccountResponse
$creadPrec :: ReadPrec RegisterAccountResponse
readList :: ReadS [RegisterAccountResponse]
$creadList :: ReadS [RegisterAccountResponse]
readsPrec :: Int -> ReadS RegisterAccountResponse
$creadsPrec :: Int -> ReadS RegisterAccountResponse
Prelude.Read, Int -> RegisterAccountResponse -> ShowS
[RegisterAccountResponse] -> ShowS
RegisterAccountResponse -> String
(Int -> RegisterAccountResponse -> ShowS)
-> (RegisterAccountResponse -> String)
-> ([RegisterAccountResponse] -> ShowS)
-> Show RegisterAccountResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterAccountResponse] -> ShowS
$cshowList :: [RegisterAccountResponse] -> ShowS
show :: RegisterAccountResponse -> String
$cshow :: RegisterAccountResponse -> String
showsPrec :: Int -> RegisterAccountResponse -> ShowS
$cshowsPrec :: Int -> RegisterAccountResponse -> ShowS
Prelude.Show, (forall x.
 RegisterAccountResponse -> Rep RegisterAccountResponse x)
-> (forall x.
    Rep RegisterAccountResponse x -> RegisterAccountResponse)
-> Generic RegisterAccountResponse
forall x. Rep RegisterAccountResponse x -> RegisterAccountResponse
forall x. RegisterAccountResponse -> Rep RegisterAccountResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterAccountResponse x -> RegisterAccountResponse
$cfrom :: forall x. RegisterAccountResponse -> Rep RegisterAccountResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterAccountResponse' 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:
--
-- 'status', 'registerAccountResponse_status' - The status of the account registration request.
--
-- 'httpStatus', 'registerAccountResponse_httpStatus' - The response's http status code.
newRegisterAccountResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RegisterAccountResponse
newRegisterAccountResponse :: Int -> RegisterAccountResponse
newRegisterAccountResponse Int
pHttpStatus_ =
  RegisterAccountResponse' :: Maybe AccountStatus -> Int -> RegisterAccountResponse
RegisterAccountResponse'
    { $sel:status:RegisterAccountResponse' :: Maybe AccountStatus
status = Maybe AccountStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RegisterAccountResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The status of the account registration request.
registerAccountResponse_status :: Lens.Lens' RegisterAccountResponse (Prelude.Maybe AccountStatus)
registerAccountResponse_status :: (Maybe AccountStatus -> f (Maybe AccountStatus))
-> RegisterAccountResponse -> f RegisterAccountResponse
registerAccountResponse_status = (RegisterAccountResponse -> Maybe AccountStatus)
-> (RegisterAccountResponse
    -> Maybe AccountStatus -> RegisterAccountResponse)
-> Lens
     RegisterAccountResponse
     RegisterAccountResponse
     (Maybe AccountStatus)
     (Maybe AccountStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterAccountResponse' {Maybe AccountStatus
status :: Maybe AccountStatus
$sel:status:RegisterAccountResponse' :: RegisterAccountResponse -> Maybe AccountStatus
status} -> Maybe AccountStatus
status) (\s :: RegisterAccountResponse
s@RegisterAccountResponse' {} Maybe AccountStatus
a -> RegisterAccountResponse
s {$sel:status:RegisterAccountResponse' :: Maybe AccountStatus
status = Maybe AccountStatus
a} :: RegisterAccountResponse)

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

instance Prelude.NFData RegisterAccountResponse