{-# 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.SecurityHub.DeleteMembers
-- 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)
--
-- Deletes the specified member accounts from Security Hub.
--
-- Can be used to delete member accounts that belong to an organization as
-- well as member accounts that were invited manually.
module Amazonka.SecurityHub.DeleteMembers
  ( -- * Creating a Request
    DeleteMembers (..),
    newDeleteMembers,

    -- * Request Lenses
    deleteMembers_accountIds,

    -- * Destructuring the Response
    DeleteMembersResponse (..),
    newDeleteMembersResponse,

    -- * Response Lenses
    deleteMembersResponse_unprocessedAccounts,
    deleteMembersResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDeleteMembers' smart constructor.
data DeleteMembers = DeleteMembers'
  { -- | The list of account IDs for the member accounts to delete.
    DeleteMembers -> [Text]
accountIds :: [Prelude.Text]
  }
  deriving (DeleteMembers -> DeleteMembers -> Bool
(DeleteMembers -> DeleteMembers -> Bool)
-> (DeleteMembers -> DeleteMembers -> Bool) -> Eq DeleteMembers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteMembers -> DeleteMembers -> Bool
$c/= :: DeleteMembers -> DeleteMembers -> Bool
== :: DeleteMembers -> DeleteMembers -> Bool
$c== :: DeleteMembers -> DeleteMembers -> Bool
Prelude.Eq, ReadPrec [DeleteMembers]
ReadPrec DeleteMembers
Int -> ReadS DeleteMembers
ReadS [DeleteMembers]
(Int -> ReadS DeleteMembers)
-> ReadS [DeleteMembers]
-> ReadPrec DeleteMembers
-> ReadPrec [DeleteMembers]
-> Read DeleteMembers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteMembers]
$creadListPrec :: ReadPrec [DeleteMembers]
readPrec :: ReadPrec DeleteMembers
$creadPrec :: ReadPrec DeleteMembers
readList :: ReadS [DeleteMembers]
$creadList :: ReadS [DeleteMembers]
readsPrec :: Int -> ReadS DeleteMembers
$creadsPrec :: Int -> ReadS DeleteMembers
Prelude.Read, Int -> DeleteMembers -> ShowS
[DeleteMembers] -> ShowS
DeleteMembers -> String
(Int -> DeleteMembers -> ShowS)
-> (DeleteMembers -> String)
-> ([DeleteMembers] -> ShowS)
-> Show DeleteMembers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteMembers] -> ShowS
$cshowList :: [DeleteMembers] -> ShowS
show :: DeleteMembers -> String
$cshow :: DeleteMembers -> String
showsPrec :: Int -> DeleteMembers -> ShowS
$cshowsPrec :: Int -> DeleteMembers -> ShowS
Prelude.Show, (forall x. DeleteMembers -> Rep DeleteMembers x)
-> (forall x. Rep DeleteMembers x -> DeleteMembers)
-> Generic DeleteMembers
forall x. Rep DeleteMembers x -> DeleteMembers
forall x. DeleteMembers -> Rep DeleteMembers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteMembers x -> DeleteMembers
$cfrom :: forall x. DeleteMembers -> Rep DeleteMembers x
Prelude.Generic)

-- |
-- Create a value of 'DeleteMembers' 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:
--
-- 'accountIds', 'deleteMembers_accountIds' - The list of account IDs for the member accounts to delete.
newDeleteMembers ::
  DeleteMembers
newDeleteMembers :: DeleteMembers
newDeleteMembers =
  DeleteMembers' :: [Text] -> DeleteMembers
DeleteMembers' {$sel:accountIds:DeleteMembers' :: [Text]
accountIds = [Text]
forall a. Monoid a => a
Prelude.mempty}

-- | The list of account IDs for the member accounts to delete.
deleteMembers_accountIds :: Lens.Lens' DeleteMembers [Prelude.Text]
deleteMembers_accountIds :: ([Text] -> f [Text]) -> DeleteMembers -> f DeleteMembers
deleteMembers_accountIds = (DeleteMembers -> [Text])
-> (DeleteMembers -> [Text] -> DeleteMembers)
-> Lens DeleteMembers DeleteMembers [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteMembers' {[Text]
accountIds :: [Text]
$sel:accountIds:DeleteMembers' :: DeleteMembers -> [Text]
accountIds} -> [Text]
accountIds) (\s :: DeleteMembers
s@DeleteMembers' {} [Text]
a -> DeleteMembers
s {$sel:accountIds:DeleteMembers' :: [Text]
accountIds = [Text]
a} :: DeleteMembers) (([Text] -> f [Text]) -> DeleteMembers -> f DeleteMembers)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> DeleteMembers
-> f DeleteMembers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest DeleteMembers where
  type
    AWSResponse DeleteMembers =
      DeleteMembersResponse
  request :: DeleteMembers -> Request DeleteMembers
request = Service -> DeleteMembers -> Request DeleteMembers
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteMembers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteMembers)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DeleteMembers))
-> Logger
-> Service
-> Proxy DeleteMembers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteMembers)))
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 [Result] -> Int -> DeleteMembersResponse
DeleteMembersResponse'
            (Maybe [Result] -> Int -> DeleteMembersResponse)
-> Either String (Maybe [Result])
-> Either String (Int -> DeleteMembersResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Either String (Maybe (Maybe [Result]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"UnprocessedAccounts"
                            Either String (Maybe (Maybe [Result]))
-> Maybe [Result] -> Either String (Maybe [Result])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Result]
forall a. Monoid a => a
Prelude.mempty
                        )
            Either String (Int -> DeleteMembersResponse)
-> Either String Int -> Either String DeleteMembersResponse
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 DeleteMembers

instance Prelude.NFData DeleteMembers

instance Core.ToHeaders DeleteMembers where
  toHeaders :: DeleteMembers -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteMembers -> 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 DeleteMembers where
  toJSON :: DeleteMembers -> Value
toJSON DeleteMembers' {[Text]
accountIds :: [Text]
$sel:accountIds:DeleteMembers' :: DeleteMembers -> [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"AccountIds" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
accountIds)]
      )

instance Core.ToPath DeleteMembers where
  toPath :: DeleteMembers -> ByteString
toPath = ByteString -> DeleteMembers -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/members/delete"

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

-- | /See:/ 'newDeleteMembersResponse' smart constructor.
data DeleteMembersResponse = DeleteMembersResponse'
  { -- | The list of Amazon Web Services accounts that were not deleted. For each
    -- account, the list includes the account ID and the email address.
    DeleteMembersResponse -> Maybe [Result]
unprocessedAccounts :: Prelude.Maybe [Result],
    -- | The response's http status code.
    DeleteMembersResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteMembersResponse -> DeleteMembersResponse -> Bool
(DeleteMembersResponse -> DeleteMembersResponse -> Bool)
-> (DeleteMembersResponse -> DeleteMembersResponse -> Bool)
-> Eq DeleteMembersResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteMembersResponse -> DeleteMembersResponse -> Bool
$c/= :: DeleteMembersResponse -> DeleteMembersResponse -> Bool
== :: DeleteMembersResponse -> DeleteMembersResponse -> Bool
$c== :: DeleteMembersResponse -> DeleteMembersResponse -> Bool
Prelude.Eq, ReadPrec [DeleteMembersResponse]
ReadPrec DeleteMembersResponse
Int -> ReadS DeleteMembersResponse
ReadS [DeleteMembersResponse]
(Int -> ReadS DeleteMembersResponse)
-> ReadS [DeleteMembersResponse]
-> ReadPrec DeleteMembersResponse
-> ReadPrec [DeleteMembersResponse]
-> Read DeleteMembersResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteMembersResponse]
$creadListPrec :: ReadPrec [DeleteMembersResponse]
readPrec :: ReadPrec DeleteMembersResponse
$creadPrec :: ReadPrec DeleteMembersResponse
readList :: ReadS [DeleteMembersResponse]
$creadList :: ReadS [DeleteMembersResponse]
readsPrec :: Int -> ReadS DeleteMembersResponse
$creadsPrec :: Int -> ReadS DeleteMembersResponse
Prelude.Read, Int -> DeleteMembersResponse -> ShowS
[DeleteMembersResponse] -> ShowS
DeleteMembersResponse -> String
(Int -> DeleteMembersResponse -> ShowS)
-> (DeleteMembersResponse -> String)
-> ([DeleteMembersResponse] -> ShowS)
-> Show DeleteMembersResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteMembersResponse] -> ShowS
$cshowList :: [DeleteMembersResponse] -> ShowS
show :: DeleteMembersResponse -> String
$cshow :: DeleteMembersResponse -> String
showsPrec :: Int -> DeleteMembersResponse -> ShowS
$cshowsPrec :: Int -> DeleteMembersResponse -> ShowS
Prelude.Show, (forall x. DeleteMembersResponse -> Rep DeleteMembersResponse x)
-> (forall x. Rep DeleteMembersResponse x -> DeleteMembersResponse)
-> Generic DeleteMembersResponse
forall x. Rep DeleteMembersResponse x -> DeleteMembersResponse
forall x. DeleteMembersResponse -> Rep DeleteMembersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteMembersResponse x -> DeleteMembersResponse
$cfrom :: forall x. DeleteMembersResponse -> Rep DeleteMembersResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteMembersResponse' 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:
--
-- 'unprocessedAccounts', 'deleteMembersResponse_unprocessedAccounts' - The list of Amazon Web Services accounts that were not deleted. For each
-- account, the list includes the account ID and the email address.
--
-- 'httpStatus', 'deleteMembersResponse_httpStatus' - The response's http status code.
newDeleteMembersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteMembersResponse
newDeleteMembersResponse :: Int -> DeleteMembersResponse
newDeleteMembersResponse Int
pHttpStatus_ =
  DeleteMembersResponse' :: Maybe [Result] -> Int -> DeleteMembersResponse
DeleteMembersResponse'
    { $sel:unprocessedAccounts:DeleteMembersResponse' :: Maybe [Result]
unprocessedAccounts =
        Maybe [Result]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteMembersResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of Amazon Web Services accounts that were not deleted. For each
-- account, the list includes the account ID and the email address.
deleteMembersResponse_unprocessedAccounts :: Lens.Lens' DeleteMembersResponse (Prelude.Maybe [Result])
deleteMembersResponse_unprocessedAccounts :: (Maybe [Result] -> f (Maybe [Result]))
-> DeleteMembersResponse -> f DeleteMembersResponse
deleteMembersResponse_unprocessedAccounts = (DeleteMembersResponse -> Maybe [Result])
-> (DeleteMembersResponse
    -> Maybe [Result] -> DeleteMembersResponse)
-> Lens
     DeleteMembersResponse
     DeleteMembersResponse
     (Maybe [Result])
     (Maybe [Result])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteMembersResponse' {Maybe [Result]
unprocessedAccounts :: Maybe [Result]
$sel:unprocessedAccounts:DeleteMembersResponse' :: DeleteMembersResponse -> Maybe [Result]
unprocessedAccounts} -> Maybe [Result]
unprocessedAccounts) (\s :: DeleteMembersResponse
s@DeleteMembersResponse' {} Maybe [Result]
a -> DeleteMembersResponse
s {$sel:unprocessedAccounts:DeleteMembersResponse' :: Maybe [Result]
unprocessedAccounts = Maybe [Result]
a} :: DeleteMembersResponse) ((Maybe [Result] -> f (Maybe [Result]))
 -> DeleteMembersResponse -> f DeleteMembersResponse)
-> ((Maybe [Result] -> f (Maybe [Result]))
    -> Maybe [Result] -> f (Maybe [Result]))
-> (Maybe [Result] -> f (Maybe [Result]))
-> DeleteMembersResponse
-> f DeleteMembersResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Result] [Result] [Result] [Result]
-> Iso
     (Maybe [Result]) (Maybe [Result]) (Maybe [Result]) (Maybe [Result])
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 AnIso [Result] [Result] [Result] [Result]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData DeleteMembersResponse