{-# 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-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)
--
-- 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 AWS 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. AWS uses the
--     payment method to charge for any billable (not free tier) AWS
--     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
--     <http://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 /AWS Organizations User Guide./
--
-- -   The account that you want to leave must not be a delegated
--     administrator account for any AWS 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. AWS
--     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.Lens as Lens
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
(RemoveAccountFromOrganization
 -> RemoveAccountFromOrganization -> Bool)
-> (RemoveAccountFromOrganization
    -> RemoveAccountFromOrganization -> Bool)
-> Eq RemoveAccountFromOrganization
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]
(Int -> ReadS RemoveAccountFromOrganization)
-> ReadS [RemoveAccountFromOrganization]
-> ReadPrec RemoveAccountFromOrganization
-> ReadPrec [RemoveAccountFromOrganization]
-> Read 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
(Int -> RemoveAccountFromOrganization -> ShowS)
-> (RemoveAccountFromOrganization -> String)
-> ([RemoveAccountFromOrganization] -> ShowS)
-> Show RemoveAccountFromOrganization
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.
 RemoveAccountFromOrganization
 -> Rep RemoveAccountFromOrganization x)
-> (forall x.
    Rep RemoveAccountFromOrganization x
    -> RemoveAccountFromOrganization)
-> Generic RemoveAccountFromOrganization
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' :: Text -> RemoveAccountFromOrganization
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 :: (Text -> f Text)
-> RemoveAccountFromOrganization -> f RemoveAccountFromOrganization
removeAccountFromOrganization_accountId = (RemoveAccountFromOrganization -> Text)
-> (RemoveAccountFromOrganization
    -> Text -> RemoveAccountFromOrganization)
-> Lens
     RemoveAccountFromOrganization
     RemoveAccountFromOrganization
     Text
     Text
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 :: RemoveAccountFromOrganization
-> Request RemoveAccountFromOrganization
request = Service
-> RemoveAccountFromOrganization
-> Request RemoveAccountFromOrganization
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RemoveAccountFromOrganization
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RemoveAccountFromOrganization)))
response =
    AWSResponse RemoveAccountFromOrganization
-> Logger
-> Service
-> Proxy RemoveAccountFromOrganization
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RemoveAccountFromOrganization)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AWSResponse RemoveAccountFromOrganization
RemoveAccountFromOrganizationResponse
RemoveAccountFromOrganizationResponse'

instance
  Prelude.Hashable
    RemoveAccountFromOrganization

instance Prelude.NFData RemoveAccountFromOrganization

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

instance Core.ToJSON RemoveAccountFromOrganization where
  toJSON :: RemoveAccountFromOrganization -> Value
toJSON RemoveAccountFromOrganization' {Text
accountId :: Text
$sel:accountId:RemoveAccountFromOrganization' :: RemoveAccountFromOrganization -> 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
"AccountId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
accountId)]
      )

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

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

-- | /See:/ 'newRemoveAccountFromOrganizationResponse' smart constructor.
data RemoveAccountFromOrganizationResponse = RemoveAccountFromOrganizationResponse'
  {
  }
  deriving (RemoveAccountFromOrganizationResponse
-> RemoveAccountFromOrganizationResponse -> Bool
(RemoveAccountFromOrganizationResponse
 -> RemoveAccountFromOrganizationResponse -> Bool)
-> (RemoveAccountFromOrganizationResponse
    -> RemoveAccountFromOrganizationResponse -> Bool)
-> Eq RemoveAccountFromOrganizationResponse
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]
(Int -> ReadS RemoveAccountFromOrganizationResponse)
-> ReadS [RemoveAccountFromOrganizationResponse]
-> ReadPrec RemoveAccountFromOrganizationResponse
-> ReadPrec [RemoveAccountFromOrganizationResponse]
-> Read 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
(Int -> RemoveAccountFromOrganizationResponse -> ShowS)
-> (RemoveAccountFromOrganizationResponse -> String)
-> ([RemoveAccountFromOrganizationResponse] -> ShowS)
-> Show RemoveAccountFromOrganizationResponse
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.
 RemoveAccountFromOrganizationResponse
 -> Rep RemoveAccountFromOrganizationResponse x)
-> (forall x.
    Rep RemoveAccountFromOrganizationResponse x
    -> RemoveAccountFromOrganizationResponse)
-> Generic RemoveAccountFromOrganizationResponse
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