{-# 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.DeleteOrganizationalUnit
-- 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 an organizational unit (OU) from a root or another OU. You must
-- first remove all accounts and child OUs from the OU that you want to
-- delete.
--
-- This operation can be called only from the organization\'s management
-- account.
module Amazonka.Organizations.DeleteOrganizationalUnit
  ( -- * Creating a Request
    DeleteOrganizationalUnit (..),
    newDeleteOrganizationalUnit,

    -- * Request Lenses
    deleteOrganizationalUnit_organizationalUnitId,

    -- * Destructuring the Response
    DeleteOrganizationalUnitResponse (..),
    newDeleteOrganizationalUnitResponse,
  )
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:/ 'newDeleteOrganizationalUnit' smart constructor.
data DeleteOrganizationalUnit = DeleteOrganizationalUnit'
  { -- | The unique identifier (ID) of the organizational unit that you want to
    -- delete. You can get the ID from the ListOrganizationalUnitsForParent
    -- operation.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for an
    -- organizational unit ID string requires \"ou-\" followed by from 4 to 32
    -- lowercase letters or digits (the ID of the root that contains the OU).
    -- This string is followed by a second \"-\" dash and from 8 to 32
    -- additional lowercase letters or digits.
    DeleteOrganizationalUnit -> Text
organizationalUnitId :: Prelude.Text
  }
  deriving (DeleteOrganizationalUnit -> DeleteOrganizationalUnit -> Bool
(DeleteOrganizationalUnit -> DeleteOrganizationalUnit -> Bool)
-> (DeleteOrganizationalUnit -> DeleteOrganizationalUnit -> Bool)
-> Eq DeleteOrganizationalUnit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteOrganizationalUnit -> DeleteOrganizationalUnit -> Bool
$c/= :: DeleteOrganizationalUnit -> DeleteOrganizationalUnit -> Bool
== :: DeleteOrganizationalUnit -> DeleteOrganizationalUnit -> Bool
$c== :: DeleteOrganizationalUnit -> DeleteOrganizationalUnit -> Bool
Prelude.Eq, ReadPrec [DeleteOrganizationalUnit]
ReadPrec DeleteOrganizationalUnit
Int -> ReadS DeleteOrganizationalUnit
ReadS [DeleteOrganizationalUnit]
(Int -> ReadS DeleteOrganizationalUnit)
-> ReadS [DeleteOrganizationalUnit]
-> ReadPrec DeleteOrganizationalUnit
-> ReadPrec [DeleteOrganizationalUnit]
-> Read DeleteOrganizationalUnit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteOrganizationalUnit]
$creadListPrec :: ReadPrec [DeleteOrganizationalUnit]
readPrec :: ReadPrec DeleteOrganizationalUnit
$creadPrec :: ReadPrec DeleteOrganizationalUnit
readList :: ReadS [DeleteOrganizationalUnit]
$creadList :: ReadS [DeleteOrganizationalUnit]
readsPrec :: Int -> ReadS DeleteOrganizationalUnit
$creadsPrec :: Int -> ReadS DeleteOrganizationalUnit
Prelude.Read, Int -> DeleteOrganizationalUnit -> ShowS
[DeleteOrganizationalUnit] -> ShowS
DeleteOrganizationalUnit -> String
(Int -> DeleteOrganizationalUnit -> ShowS)
-> (DeleteOrganizationalUnit -> String)
-> ([DeleteOrganizationalUnit] -> ShowS)
-> Show DeleteOrganizationalUnit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteOrganizationalUnit] -> ShowS
$cshowList :: [DeleteOrganizationalUnit] -> ShowS
show :: DeleteOrganizationalUnit -> String
$cshow :: DeleteOrganizationalUnit -> String
showsPrec :: Int -> DeleteOrganizationalUnit -> ShowS
$cshowsPrec :: Int -> DeleteOrganizationalUnit -> ShowS
Prelude.Show, (forall x.
 DeleteOrganizationalUnit -> Rep DeleteOrganizationalUnit x)
-> (forall x.
    Rep DeleteOrganizationalUnit x -> DeleteOrganizationalUnit)
-> Generic DeleteOrganizationalUnit
forall x.
Rep DeleteOrganizationalUnit x -> DeleteOrganizationalUnit
forall x.
DeleteOrganizationalUnit -> Rep DeleteOrganizationalUnit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeleteOrganizationalUnit x -> DeleteOrganizationalUnit
$cfrom :: forall x.
DeleteOrganizationalUnit -> Rep DeleteOrganizationalUnit x
Prelude.Generic)

-- |
-- Create a value of 'DeleteOrganizationalUnit' 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:
--
-- 'organizationalUnitId', 'deleteOrganizationalUnit_organizationalUnitId' - The unique identifier (ID) of the organizational unit that you want to
-- delete. You can get the ID from the ListOrganizationalUnitsForParent
-- operation.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for an
-- organizational unit ID string requires \"ou-\" followed by from 4 to 32
-- lowercase letters or digits (the ID of the root that contains the OU).
-- This string is followed by a second \"-\" dash and from 8 to 32
-- additional lowercase letters or digits.
newDeleteOrganizationalUnit ::
  -- | 'organizationalUnitId'
  Prelude.Text ->
  DeleteOrganizationalUnit
newDeleteOrganizationalUnit :: Text -> DeleteOrganizationalUnit
newDeleteOrganizationalUnit Text
pOrganizationalUnitId_ =
  DeleteOrganizationalUnit' :: Text -> DeleteOrganizationalUnit
DeleteOrganizationalUnit'
    { $sel:organizationalUnitId:DeleteOrganizationalUnit' :: Text
organizationalUnitId =
        Text
pOrganizationalUnitId_
    }

-- | The unique identifier (ID) of the organizational unit that you want to
-- delete. You can get the ID from the ListOrganizationalUnitsForParent
-- operation.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for an
-- organizational unit ID string requires \"ou-\" followed by from 4 to 32
-- lowercase letters or digits (the ID of the root that contains the OU).
-- This string is followed by a second \"-\" dash and from 8 to 32
-- additional lowercase letters or digits.
deleteOrganizationalUnit_organizationalUnitId :: Lens.Lens' DeleteOrganizationalUnit Prelude.Text
deleteOrganizationalUnit_organizationalUnitId :: (Text -> f Text)
-> DeleteOrganizationalUnit -> f DeleteOrganizationalUnit
deleteOrganizationalUnit_organizationalUnitId = (DeleteOrganizationalUnit -> Text)
-> (DeleteOrganizationalUnit -> Text -> DeleteOrganizationalUnit)
-> Lens DeleteOrganizationalUnit DeleteOrganizationalUnit Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteOrganizationalUnit' {Text
organizationalUnitId :: Text
$sel:organizationalUnitId:DeleteOrganizationalUnit' :: DeleteOrganizationalUnit -> Text
organizationalUnitId} -> Text
organizationalUnitId) (\s :: DeleteOrganizationalUnit
s@DeleteOrganizationalUnit' {} Text
a -> DeleteOrganizationalUnit
s {$sel:organizationalUnitId:DeleteOrganizationalUnit' :: Text
organizationalUnitId = Text
a} :: DeleteOrganizationalUnit)

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

instance Prelude.Hashable DeleteOrganizationalUnit

instance Prelude.NFData DeleteOrganizationalUnit

instance Core.ToHeaders DeleteOrganizationalUnit where
  toHeaders :: DeleteOrganizationalUnit -> [Header]
toHeaders =
    [Header] -> DeleteOrganizationalUnit -> [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.DeleteOrganizationalUnit" ::
                          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 DeleteOrganizationalUnit where
  toJSON :: DeleteOrganizationalUnit -> Value
toJSON DeleteOrganizationalUnit' {Text
organizationalUnitId :: Text
$sel:organizationalUnitId:DeleteOrganizationalUnit' :: DeleteOrganizationalUnit -> 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
"OrganizationalUnitId"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
organizationalUnitId
              )
          ]
      )

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

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

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

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

instance
  Prelude.NFData
    DeleteOrganizationalUnitResponse