{-# 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.GuardDuty.DisassociateMembers
-- 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)
--
-- Disassociates GuardDuty member accounts (to the current GuardDuty
-- administrator account) specified by the account IDs.
module Amazonka.GuardDuty.DisassociateMembers
  ( -- * Creating a Request
    DisassociateMembers (..),
    newDisassociateMembers,

    -- * Request Lenses
    disassociateMembers_detectorId,
    disassociateMembers_accountIds,

    -- * Destructuring the Response
    DisassociateMembersResponse (..),
    newDisassociateMembersResponse,

    -- * Response Lenses
    disassociateMembersResponse_httpStatus,
    disassociateMembersResponse_unprocessedAccounts,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.GuardDuty.Types
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:/ 'newDisassociateMembers' smart constructor.
data DisassociateMembers = DisassociateMembers'
  { -- | The unique ID of the detector of the GuardDuty account whose members you
    -- want to disassociate from the administrator account.
    DisassociateMembers -> Text
detectorId :: Prelude.Text,
    -- | A list of account IDs of the GuardDuty member accounts that you want to
    -- disassociate from the administrator account.
    DisassociateMembers -> NonEmpty Text
accountIds :: Prelude.NonEmpty Prelude.Text
  }
  deriving (DisassociateMembers -> DisassociateMembers -> Bool
(DisassociateMembers -> DisassociateMembers -> Bool)
-> (DisassociateMembers -> DisassociateMembers -> Bool)
-> Eq DisassociateMembers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DisassociateMembers -> DisassociateMembers -> Bool
$c/= :: DisassociateMembers -> DisassociateMembers -> Bool
== :: DisassociateMembers -> DisassociateMembers -> Bool
$c== :: DisassociateMembers -> DisassociateMembers -> Bool
Prelude.Eq, ReadPrec [DisassociateMembers]
ReadPrec DisassociateMembers
Int -> ReadS DisassociateMembers
ReadS [DisassociateMembers]
(Int -> ReadS DisassociateMembers)
-> ReadS [DisassociateMembers]
-> ReadPrec DisassociateMembers
-> ReadPrec [DisassociateMembers]
-> Read DisassociateMembers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DisassociateMembers]
$creadListPrec :: ReadPrec [DisassociateMembers]
readPrec :: ReadPrec DisassociateMembers
$creadPrec :: ReadPrec DisassociateMembers
readList :: ReadS [DisassociateMembers]
$creadList :: ReadS [DisassociateMembers]
readsPrec :: Int -> ReadS DisassociateMembers
$creadsPrec :: Int -> ReadS DisassociateMembers
Prelude.Read, Int -> DisassociateMembers -> ShowS
[DisassociateMembers] -> ShowS
DisassociateMembers -> String
(Int -> DisassociateMembers -> ShowS)
-> (DisassociateMembers -> String)
-> ([DisassociateMembers] -> ShowS)
-> Show DisassociateMembers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DisassociateMembers] -> ShowS
$cshowList :: [DisassociateMembers] -> ShowS
show :: DisassociateMembers -> String
$cshow :: DisassociateMembers -> String
showsPrec :: Int -> DisassociateMembers -> ShowS
$cshowsPrec :: Int -> DisassociateMembers -> ShowS
Prelude.Show, (forall x. DisassociateMembers -> Rep DisassociateMembers x)
-> (forall x. Rep DisassociateMembers x -> DisassociateMembers)
-> Generic DisassociateMembers
forall x. Rep DisassociateMembers x -> DisassociateMembers
forall x. DisassociateMembers -> Rep DisassociateMembers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DisassociateMembers x -> DisassociateMembers
$cfrom :: forall x. DisassociateMembers -> Rep DisassociateMembers x
Prelude.Generic)

-- |
-- Create a value of 'DisassociateMembers' 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:
--
-- 'detectorId', 'disassociateMembers_detectorId' - The unique ID of the detector of the GuardDuty account whose members you
-- want to disassociate from the administrator account.
--
-- 'accountIds', 'disassociateMembers_accountIds' - A list of account IDs of the GuardDuty member accounts that you want to
-- disassociate from the administrator account.
newDisassociateMembers ::
  -- | 'detectorId'
  Prelude.Text ->
  -- | 'accountIds'
  Prelude.NonEmpty Prelude.Text ->
  DisassociateMembers
newDisassociateMembers :: Text -> NonEmpty Text -> DisassociateMembers
newDisassociateMembers Text
pDetectorId_ NonEmpty Text
pAccountIds_ =
  DisassociateMembers' :: Text -> NonEmpty Text -> DisassociateMembers
DisassociateMembers'
    { $sel:detectorId:DisassociateMembers' :: Text
detectorId = Text
pDetectorId_,
      $sel:accountIds:DisassociateMembers' :: NonEmpty Text
accountIds = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pAccountIds_
    }

-- | The unique ID of the detector of the GuardDuty account whose members you
-- want to disassociate from the administrator account.
disassociateMembers_detectorId :: Lens.Lens' DisassociateMembers Prelude.Text
disassociateMembers_detectorId :: (Text -> f Text) -> DisassociateMembers -> f DisassociateMembers
disassociateMembers_detectorId = (DisassociateMembers -> Text)
-> (DisassociateMembers -> Text -> DisassociateMembers)
-> Lens DisassociateMembers DisassociateMembers Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisassociateMembers' {Text
detectorId :: Text
$sel:detectorId:DisassociateMembers' :: DisassociateMembers -> Text
detectorId} -> Text
detectorId) (\s :: DisassociateMembers
s@DisassociateMembers' {} Text
a -> DisassociateMembers
s {$sel:detectorId:DisassociateMembers' :: Text
detectorId = Text
a} :: DisassociateMembers)

-- | A list of account IDs of the GuardDuty member accounts that you want to
-- disassociate from the administrator account.
disassociateMembers_accountIds :: Lens.Lens' DisassociateMembers (Prelude.NonEmpty Prelude.Text)
disassociateMembers_accountIds :: (NonEmpty Text -> f (NonEmpty Text))
-> DisassociateMembers -> f DisassociateMembers
disassociateMembers_accountIds = (DisassociateMembers -> NonEmpty Text)
-> (DisassociateMembers -> NonEmpty Text -> DisassociateMembers)
-> Lens
     DisassociateMembers
     DisassociateMembers
     (NonEmpty Text)
     (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisassociateMembers' {NonEmpty Text
accountIds :: NonEmpty Text
$sel:accountIds:DisassociateMembers' :: DisassociateMembers -> NonEmpty Text
accountIds} -> NonEmpty Text
accountIds) (\s :: DisassociateMembers
s@DisassociateMembers' {} NonEmpty Text
a -> DisassociateMembers
s {$sel:accountIds:DisassociateMembers' :: NonEmpty Text
accountIds = NonEmpty Text
a} :: DisassociateMembers) ((NonEmpty Text -> f (NonEmpty Text))
 -> DisassociateMembers -> f DisassociateMembers)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> DisassociateMembers
-> f DisassociateMembers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable DisassociateMembers

instance Prelude.NFData DisassociateMembers

instance Core.ToHeaders DisassociateMembers where
  toHeaders :: DisassociateMembers -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DisassociateMembers -> 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 DisassociateMembers where
  toJSON :: DisassociateMembers -> Value
toJSON DisassociateMembers' {NonEmpty Text
Text
accountIds :: NonEmpty Text
detectorId :: Text
$sel:accountIds:DisassociateMembers' :: DisassociateMembers -> NonEmpty Text
$sel:detectorId:DisassociateMembers' :: DisassociateMembers -> 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 -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
accountIds)]
      )

instance Core.ToPath DisassociateMembers where
  toPath :: DisassociateMembers -> ByteString
toPath DisassociateMembers' {NonEmpty Text
Text
accountIds :: NonEmpty Text
detectorId :: Text
$sel:accountIds:DisassociateMembers' :: DisassociateMembers -> NonEmpty Text
$sel:detectorId:DisassociateMembers' :: DisassociateMembers -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/detector/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
detectorId,
        ByteString
"/member/disassociate"
      ]

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

-- | /See:/ 'newDisassociateMembersResponse' smart constructor.
data DisassociateMembersResponse = DisassociateMembersResponse'
  { -- | The response's http status code.
    DisassociateMembersResponse -> Int
httpStatus :: Prelude.Int,
    -- | A list of objects that contain the unprocessed account and a result
    -- string that explains why it was unprocessed.
    DisassociateMembersResponse -> [UnprocessedAccount]
unprocessedAccounts :: [UnprocessedAccount]
  }
  deriving (DisassociateMembersResponse -> DisassociateMembersResponse -> Bool
(DisassociateMembersResponse
 -> DisassociateMembersResponse -> Bool)
-> (DisassociateMembersResponse
    -> DisassociateMembersResponse -> Bool)
-> Eq DisassociateMembersResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DisassociateMembersResponse -> DisassociateMembersResponse -> Bool
$c/= :: DisassociateMembersResponse -> DisassociateMembersResponse -> Bool
== :: DisassociateMembersResponse -> DisassociateMembersResponse -> Bool
$c== :: DisassociateMembersResponse -> DisassociateMembersResponse -> Bool
Prelude.Eq, ReadPrec [DisassociateMembersResponse]
ReadPrec DisassociateMembersResponse
Int -> ReadS DisassociateMembersResponse
ReadS [DisassociateMembersResponse]
(Int -> ReadS DisassociateMembersResponse)
-> ReadS [DisassociateMembersResponse]
-> ReadPrec DisassociateMembersResponse
-> ReadPrec [DisassociateMembersResponse]
-> Read DisassociateMembersResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DisassociateMembersResponse]
$creadListPrec :: ReadPrec [DisassociateMembersResponse]
readPrec :: ReadPrec DisassociateMembersResponse
$creadPrec :: ReadPrec DisassociateMembersResponse
readList :: ReadS [DisassociateMembersResponse]
$creadList :: ReadS [DisassociateMembersResponse]
readsPrec :: Int -> ReadS DisassociateMembersResponse
$creadsPrec :: Int -> ReadS DisassociateMembersResponse
Prelude.Read, Int -> DisassociateMembersResponse -> ShowS
[DisassociateMembersResponse] -> ShowS
DisassociateMembersResponse -> String
(Int -> DisassociateMembersResponse -> ShowS)
-> (DisassociateMembersResponse -> String)
-> ([DisassociateMembersResponse] -> ShowS)
-> Show DisassociateMembersResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DisassociateMembersResponse] -> ShowS
$cshowList :: [DisassociateMembersResponse] -> ShowS
show :: DisassociateMembersResponse -> String
$cshow :: DisassociateMembersResponse -> String
showsPrec :: Int -> DisassociateMembersResponse -> ShowS
$cshowsPrec :: Int -> DisassociateMembersResponse -> ShowS
Prelude.Show, (forall x.
 DisassociateMembersResponse -> Rep DisassociateMembersResponse x)
-> (forall x.
    Rep DisassociateMembersResponse x -> DisassociateMembersResponse)
-> Generic DisassociateMembersResponse
forall x.
Rep DisassociateMembersResponse x -> DisassociateMembersResponse
forall x.
DisassociateMembersResponse -> Rep DisassociateMembersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DisassociateMembersResponse x -> DisassociateMembersResponse
$cfrom :: forall x.
DisassociateMembersResponse -> Rep DisassociateMembersResponse x
Prelude.Generic)

-- |
-- Create a value of 'DisassociateMembersResponse' 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:
--
-- 'httpStatus', 'disassociateMembersResponse_httpStatus' - The response's http status code.
--
-- 'unprocessedAccounts', 'disassociateMembersResponse_unprocessedAccounts' - A list of objects that contain the unprocessed account and a result
-- string that explains why it was unprocessed.
newDisassociateMembersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DisassociateMembersResponse
newDisassociateMembersResponse :: Int -> DisassociateMembersResponse
newDisassociateMembersResponse Int
pHttpStatus_ =
  DisassociateMembersResponse' :: Int -> [UnprocessedAccount] -> DisassociateMembersResponse
DisassociateMembersResponse'
    { $sel:httpStatus:DisassociateMembersResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:unprocessedAccounts:DisassociateMembersResponse' :: [UnprocessedAccount]
unprocessedAccounts = [UnprocessedAccount]
forall a. Monoid a => a
Prelude.mempty
    }

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

-- | A list of objects that contain the unprocessed account and a result
-- string that explains why it was unprocessed.
disassociateMembersResponse_unprocessedAccounts :: Lens.Lens' DisassociateMembersResponse [UnprocessedAccount]
disassociateMembersResponse_unprocessedAccounts :: ([UnprocessedAccount] -> f [UnprocessedAccount])
-> DisassociateMembersResponse -> f DisassociateMembersResponse
disassociateMembersResponse_unprocessedAccounts = (DisassociateMembersResponse -> [UnprocessedAccount])
-> (DisassociateMembersResponse
    -> [UnprocessedAccount] -> DisassociateMembersResponse)
-> Lens
     DisassociateMembersResponse
     DisassociateMembersResponse
     [UnprocessedAccount]
     [UnprocessedAccount]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisassociateMembersResponse' {[UnprocessedAccount]
unprocessedAccounts :: [UnprocessedAccount]
$sel:unprocessedAccounts:DisassociateMembersResponse' :: DisassociateMembersResponse -> [UnprocessedAccount]
unprocessedAccounts} -> [UnprocessedAccount]
unprocessedAccounts) (\s :: DisassociateMembersResponse
s@DisassociateMembersResponse' {} [UnprocessedAccount]
a -> DisassociateMembersResponse
s {$sel:unprocessedAccounts:DisassociateMembersResponse' :: [UnprocessedAccount]
unprocessedAccounts = [UnprocessedAccount]
a} :: DisassociateMembersResponse) (([UnprocessedAccount] -> f [UnprocessedAccount])
 -> DisassociateMembersResponse -> f DisassociateMembersResponse)
-> (([UnprocessedAccount] -> f [UnprocessedAccount])
    -> [UnprocessedAccount] -> f [UnprocessedAccount])
-> ([UnprocessedAccount] -> f [UnprocessedAccount])
-> DisassociateMembersResponse
-> f DisassociateMembersResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([UnprocessedAccount] -> f [UnprocessedAccount])
-> [UnprocessedAccount] -> f [UnprocessedAccount]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData DisassociateMembersResponse