{-# 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.Organizations.RemoveAccountFromOrganization
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Removes the specified account from the organization.
--
-- The removed account becomes a standalone account that isn\'t a member of
-- any organization. It\'s no longer subject to any policies and is
-- responsible for its own bill payments. The organization\'s management
-- account is no longer charged for any expenses accrued by the member
-- account after it\'s removed from the organization.
--
-- This operation can be called only from the organization\'s management
-- account. Member accounts can remove themselves with LeaveOrganization
-- instead.
--
-- -   You can remove an account from your organization only if the account
--     is configured with the information required to operate as a
--     standalone account. When you create an account in an organization
--     using the Organizations console, API, or CLI commands, the
--     information required of standalone accounts is /not/ automatically
--     collected. For an account that you want to make standalone, you must
--     choose a support plan, provide and verify the required contact
--     information, and provide a current payment method. Amazon Web
--     Services uses the payment method to charge for any billable (not
--     free tier) Amazon Web Services activity that occurs while the
--     account isn\'t attached to an organization. To remove an account
--     that doesn\'t yet have this information, you must sign in as the
--     member account and follow the steps at
--     <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_accounts_remove.html#leave-without-all-info To leave an organization when all required account information has not yet been provided>
--     in the /Organizations User Guide./
--
-- -   The account that you want to leave must not be a delegated
--     administrator account for any Amazon Web Services service enabled
--     for your organization. If the account is a delegated administrator,
--     you must first change the delegated administrator account to another
--     account that is remaining in the organization.
--
-- -   After the account leaves the organization, all tags that were
--     attached to the account object in the organization are deleted.
--     Amazon Web Services accounts outside of an organization do not
--     support tags.
module Amazonka.Organizations.RemoveAccountFromOrganization
  ( -- * Creating a Request
    RemoveAccountFromOrganization (..),
    newRemoveAccountFromOrganization,

    -- * Request Lenses
    removeAccountFromOrganization_accountId,

    -- * Destructuring the Response
    RemoveAccountFromOrganizationResponse (..),
    newRemoveAccountFromOrganizationResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Organizations.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRemoveAccountFromOrganization' smart constructor.
data RemoveAccountFromOrganization = RemoveAccountFromOrganization'
  { -- | The unique identifier (ID) of the member account that you want to remove
    -- from the organization.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for an account ID
    -- string requires exactly 12 digits.
    RemoveAccountFromOrganization -> Text
accountId :: Prelude.Text
  }
  deriving (RemoveAccountFromOrganization
-> RemoveAccountFromOrganization -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RemoveAccountFromOrganization
-> RemoveAccountFromOrganization -> Bool
$c/= :: RemoveAccountFromOrganization
-> RemoveAccountFromOrganization -> Bool
== :: RemoveAccountFromOrganization
-> RemoveAccountFromOrganization -> Bool
$c== :: RemoveAccountFromOrganization
-> RemoveAccountFromOrganization -> Bool
Prelude.Eq, ReadPrec [RemoveAccountFromOrganization]
ReadPrec RemoveAccountFromOrganization
Int -> ReadS RemoveAccountFromOrganization
ReadS [RemoveAccountFromOrganization]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RemoveAccountFromOrganization]
$creadListPrec :: ReadPrec [RemoveAccountFromOrganization]
readPrec :: ReadPrec RemoveAccountFromOrganization
$creadPrec :: ReadPrec RemoveAccountFromOrganization
readList :: ReadS [RemoveAccountFromOrganization]
$creadList :: ReadS [RemoveAccountFromOrganization]
readsPrec :: Int -> ReadS RemoveAccountFromOrganization
$creadsPrec :: Int -> ReadS RemoveAccountFromOrganization
Prelude.Read, Int -> RemoveAccountFromOrganization -> ShowS
[RemoveAccountFromOrganization] -> ShowS
RemoveAccountFromOrganization -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RemoveAccountFromOrganization] -> ShowS
$cshowList :: [RemoveAccountFromOrganization] -> ShowS
show :: RemoveAccountFromOrganization -> String
$cshow :: RemoveAccountFromOrganization -> String
showsPrec :: Int -> RemoveAccountFromOrganization -> ShowS
$cshowsPrec :: Int -> RemoveAccountFromOrganization -> ShowS
Prelude.Show, forall x.
Rep RemoveAccountFromOrganization x
-> RemoveAccountFromOrganization
forall x.
RemoveAccountFromOrganization
-> Rep RemoveAccountFromOrganization x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RemoveAccountFromOrganization x
-> RemoveAccountFromOrganization
$cfrom :: forall x.
RemoveAccountFromOrganization
-> Rep RemoveAccountFromOrganization x
Prelude.Generic)

-- |
-- Create a value of 'RemoveAccountFromOrganization' 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:
--
-- 'accountId', 'removeAccountFromOrganization_accountId' - The unique identifier (ID) of the member account that you want to remove
-- from the organization.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for an account ID
-- string requires exactly 12 digits.
newRemoveAccountFromOrganization ::
  -- | 'accountId'
  Prelude.Text ->
  RemoveAccountFromOrganization
newRemoveAccountFromOrganization :: Text -> RemoveAccountFromOrganization
newRemoveAccountFromOrganization Text
pAccountId_ =
  RemoveAccountFromOrganization'
    { $sel:accountId:RemoveAccountFromOrganization' :: Text
accountId =
        Text
pAccountId_
    }

-- | The unique identifier (ID) of the member account that you want to remove
-- from the organization.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for an account ID
-- string requires exactly 12 digits.
removeAccountFromOrganization_accountId :: Lens.Lens' RemoveAccountFromOrganization Prelude.Text
removeAccountFromOrganization_accountId :: Lens' RemoveAccountFromOrganization Text
removeAccountFromOrganization_accountId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RemoveAccountFromOrganization' {Text
accountId :: Text
$sel:accountId:RemoveAccountFromOrganization' :: RemoveAccountFromOrganization -> Text
accountId} -> Text
accountId) (\s :: RemoveAccountFromOrganization
s@RemoveAccountFromOrganization' {} Text
a -> RemoveAccountFromOrganization
s {$sel:accountId:RemoveAccountFromOrganization' :: Text
accountId = Text
a} :: RemoveAccountFromOrganization)

instance
  Core.AWSRequest
    RemoveAccountFromOrganization
  where
  type
    AWSResponse RemoveAccountFromOrganization =
      RemoveAccountFromOrganizationResponse
  request :: (Service -> Service)
-> RemoveAccountFromOrganization
-> Request RemoveAccountFromOrganization
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy RemoveAccountFromOrganization
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RemoveAccountFromOrganization)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      RemoveAccountFromOrganizationResponse
RemoveAccountFromOrganizationResponse'

instance
  Prelude.Hashable
    RemoveAccountFromOrganization
  where
  hashWithSalt :: Int -> RemoveAccountFromOrganization -> Int
hashWithSalt Int
_salt RemoveAccountFromOrganization' {Text
accountId :: Text
$sel:accountId:RemoveAccountFromOrganization' :: RemoveAccountFromOrganization -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
accountId

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

instance Data.ToHeaders RemoveAccountFromOrganization where
  toHeaders :: RemoveAccountFromOrganization -> [Header]
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"AWSOrganizationsV20161128.RemoveAccountFromOrganization" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON RemoveAccountFromOrganization where
  toJSON :: RemoveAccountFromOrganization -> Value
toJSON RemoveAccountFromOrganization' {Text
accountId :: Text
$sel:accountId:RemoveAccountFromOrganization' :: RemoveAccountFromOrganization -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"AccountId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
accountId)]
      )

instance Data.ToPath RemoveAccountFromOrganization where
  toPath :: RemoveAccountFromOrganization -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newRemoveAccountFromOrganizationResponse' smart constructor.
data RemoveAccountFromOrganizationResponse = RemoveAccountFromOrganizationResponse'
  {
  }
  deriving (RemoveAccountFromOrganizationResponse
-> RemoveAccountFromOrganizationResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RemoveAccountFromOrganizationResponse
-> RemoveAccountFromOrganizationResponse -> Bool
$c/= :: RemoveAccountFromOrganizationResponse
-> RemoveAccountFromOrganizationResponse -> Bool
== :: RemoveAccountFromOrganizationResponse
-> RemoveAccountFromOrganizationResponse -> Bool
$c== :: RemoveAccountFromOrganizationResponse
-> RemoveAccountFromOrganizationResponse -> Bool
Prelude.Eq, ReadPrec [RemoveAccountFromOrganizationResponse]
ReadPrec RemoveAccountFromOrganizationResponse
Int -> ReadS RemoveAccountFromOrganizationResponse
ReadS [RemoveAccountFromOrganizationResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RemoveAccountFromOrganizationResponse]
$creadListPrec :: ReadPrec [RemoveAccountFromOrganizationResponse]
readPrec :: ReadPrec RemoveAccountFromOrganizationResponse
$creadPrec :: ReadPrec RemoveAccountFromOrganizationResponse
readList :: ReadS [RemoveAccountFromOrganizationResponse]
$creadList :: ReadS [RemoveAccountFromOrganizationResponse]
readsPrec :: Int -> ReadS RemoveAccountFromOrganizationResponse
$creadsPrec :: Int -> ReadS RemoveAccountFromOrganizationResponse
Prelude.Read, Int -> RemoveAccountFromOrganizationResponse -> ShowS
[RemoveAccountFromOrganizationResponse] -> ShowS
RemoveAccountFromOrganizationResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RemoveAccountFromOrganizationResponse] -> ShowS
$cshowList :: [RemoveAccountFromOrganizationResponse] -> ShowS
show :: RemoveAccountFromOrganizationResponse -> String
$cshow :: RemoveAccountFromOrganizationResponse -> String
showsPrec :: Int -> RemoveAccountFromOrganizationResponse -> ShowS
$cshowsPrec :: Int -> RemoveAccountFromOrganizationResponse -> ShowS
Prelude.Show, forall x.
Rep RemoveAccountFromOrganizationResponse x
-> RemoveAccountFromOrganizationResponse
forall x.
RemoveAccountFromOrganizationResponse
-> Rep RemoveAccountFromOrganizationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RemoveAccountFromOrganizationResponse x
-> RemoveAccountFromOrganizationResponse
$cfrom :: forall x.
RemoveAccountFromOrganizationResponse
-> Rep RemoveAccountFromOrganizationResponse x
Prelude.Generic)

-- |
-- Create a value of 'RemoveAccountFromOrganizationResponse' 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.
newRemoveAccountFromOrganizationResponse ::
  RemoveAccountFromOrganizationResponse
newRemoveAccountFromOrganizationResponse :: RemoveAccountFromOrganizationResponse
newRemoveAccountFromOrganizationResponse =
  RemoveAccountFromOrganizationResponse
RemoveAccountFromOrganizationResponse'

instance
  Prelude.NFData
    RemoveAccountFromOrganizationResponse
  where
  rnf :: RemoveAccountFromOrganizationResponse -> ()
rnf RemoveAccountFromOrganizationResponse
_ = ()