{-# 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.DescribeOrganizationalUnit
-- 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)
--
-- Retrieves information about an organizational unit (OU).
--
-- This operation can be called only from the organization\'s management
-- account or by a member account that is a delegated administrator for an
-- AWS service.
module Amazonka.Organizations.DescribeOrganizationalUnit
  ( -- * Creating a Request
    DescribeOrganizationalUnit (..),
    newDescribeOrganizationalUnit,

    -- * Request Lenses
    describeOrganizationalUnit_organizationalUnitId,

    -- * Destructuring the Response
    DescribeOrganizationalUnitResponse (..),
    newDescribeOrganizationalUnitResponse,

    -- * Response Lenses
    describeOrganizationalUnitResponse_organizationalUnit,
    describeOrganizationalUnitResponse_httpStatus,
  )
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:/ 'newDescribeOrganizationalUnit' smart constructor.
data DescribeOrganizationalUnit = DescribeOrganizationalUnit'
  { -- | The unique identifier (ID) of the organizational unit that you want
    -- details about. 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.
    DescribeOrganizationalUnit -> Text
organizationalUnitId :: Prelude.Text
  }
  deriving (DescribeOrganizationalUnit -> DescribeOrganizationalUnit -> Bool
(DescribeOrganizationalUnit -> DescribeOrganizationalUnit -> Bool)
-> (DescribeOrganizationalUnit
    -> DescribeOrganizationalUnit -> Bool)
-> Eq DescribeOrganizationalUnit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeOrganizationalUnit -> DescribeOrganizationalUnit -> Bool
$c/= :: DescribeOrganizationalUnit -> DescribeOrganizationalUnit -> Bool
== :: DescribeOrganizationalUnit -> DescribeOrganizationalUnit -> Bool
$c== :: DescribeOrganizationalUnit -> DescribeOrganizationalUnit -> Bool
Prelude.Eq, ReadPrec [DescribeOrganizationalUnit]
ReadPrec DescribeOrganizationalUnit
Int -> ReadS DescribeOrganizationalUnit
ReadS [DescribeOrganizationalUnit]
(Int -> ReadS DescribeOrganizationalUnit)
-> ReadS [DescribeOrganizationalUnit]
-> ReadPrec DescribeOrganizationalUnit
-> ReadPrec [DescribeOrganizationalUnit]
-> Read DescribeOrganizationalUnit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeOrganizationalUnit]
$creadListPrec :: ReadPrec [DescribeOrganizationalUnit]
readPrec :: ReadPrec DescribeOrganizationalUnit
$creadPrec :: ReadPrec DescribeOrganizationalUnit
readList :: ReadS [DescribeOrganizationalUnit]
$creadList :: ReadS [DescribeOrganizationalUnit]
readsPrec :: Int -> ReadS DescribeOrganizationalUnit
$creadsPrec :: Int -> ReadS DescribeOrganizationalUnit
Prelude.Read, Int -> DescribeOrganizationalUnit -> ShowS
[DescribeOrganizationalUnit] -> ShowS
DescribeOrganizationalUnit -> String
(Int -> DescribeOrganizationalUnit -> ShowS)
-> (DescribeOrganizationalUnit -> String)
-> ([DescribeOrganizationalUnit] -> ShowS)
-> Show DescribeOrganizationalUnit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeOrganizationalUnit] -> ShowS
$cshowList :: [DescribeOrganizationalUnit] -> ShowS
show :: DescribeOrganizationalUnit -> String
$cshow :: DescribeOrganizationalUnit -> String
showsPrec :: Int -> DescribeOrganizationalUnit -> ShowS
$cshowsPrec :: Int -> DescribeOrganizationalUnit -> ShowS
Prelude.Show, (forall x.
 DescribeOrganizationalUnit -> Rep DescribeOrganizationalUnit x)
-> (forall x.
    Rep DescribeOrganizationalUnit x -> DescribeOrganizationalUnit)
-> Generic DescribeOrganizationalUnit
forall x.
Rep DescribeOrganizationalUnit x -> DescribeOrganizationalUnit
forall x.
DescribeOrganizationalUnit -> Rep DescribeOrganizationalUnit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeOrganizationalUnit x -> DescribeOrganizationalUnit
$cfrom :: forall x.
DescribeOrganizationalUnit -> Rep DescribeOrganizationalUnit x
Prelude.Generic)

-- |
-- Create a value of 'DescribeOrganizationalUnit' 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', 'describeOrganizationalUnit_organizationalUnitId' - The unique identifier (ID) of the organizational unit that you want
-- details about. 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.
newDescribeOrganizationalUnit ::
  -- | 'organizationalUnitId'
  Prelude.Text ->
  DescribeOrganizationalUnit
newDescribeOrganizationalUnit :: Text -> DescribeOrganizationalUnit
newDescribeOrganizationalUnit Text
pOrganizationalUnitId_ =
  DescribeOrganizationalUnit' :: Text -> DescribeOrganizationalUnit
DescribeOrganizationalUnit'
    { $sel:organizationalUnitId:DescribeOrganizationalUnit' :: Text
organizationalUnitId =
        Text
pOrganizationalUnitId_
    }

-- | The unique identifier (ID) of the organizational unit that you want
-- details about. 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.
describeOrganizationalUnit_organizationalUnitId :: Lens.Lens' DescribeOrganizationalUnit Prelude.Text
describeOrganizationalUnit_organizationalUnitId :: (Text -> f Text)
-> DescribeOrganizationalUnit -> f DescribeOrganizationalUnit
describeOrganizationalUnit_organizationalUnitId = (DescribeOrganizationalUnit -> Text)
-> (DescribeOrganizationalUnit
    -> Text -> DescribeOrganizationalUnit)
-> Lens
     DescribeOrganizationalUnit DescribeOrganizationalUnit Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeOrganizationalUnit' {Text
organizationalUnitId :: Text
$sel:organizationalUnitId:DescribeOrganizationalUnit' :: DescribeOrganizationalUnit -> Text
organizationalUnitId} -> Text
organizationalUnitId) (\s :: DescribeOrganizationalUnit
s@DescribeOrganizationalUnit' {} Text
a -> DescribeOrganizationalUnit
s {$sel:organizationalUnitId:DescribeOrganizationalUnit' :: Text
organizationalUnitId = Text
a} :: DescribeOrganizationalUnit)

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

instance Prelude.NFData DescribeOrganizationalUnit

instance Core.ToHeaders DescribeOrganizationalUnit where
  toHeaders :: DescribeOrganizationalUnit -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeOrganizationalUnit -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"AWSOrganizationsV20161128.DescribeOrganizationalUnit" ::
                          Prelude.ByteString
                      ),
            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 DescribeOrganizationalUnit where
  toJSON :: DescribeOrganizationalUnit -> Value
toJSON DescribeOrganizationalUnit' {Text
organizationalUnitId :: Text
$sel:organizationalUnitId:DescribeOrganizationalUnit' :: DescribeOrganizationalUnit -> 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 DescribeOrganizationalUnit where
  toPath :: DescribeOrganizationalUnit -> ByteString
toPath = ByteString -> DescribeOrganizationalUnit -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newDescribeOrganizationalUnitResponse' smart constructor.
data DescribeOrganizationalUnitResponse = DescribeOrganizationalUnitResponse'
  { -- | A structure that contains details about the specified OU.
    DescribeOrganizationalUnitResponse -> Maybe OrganizationalUnit
organizationalUnit :: Prelude.Maybe OrganizationalUnit,
    -- | The response's http status code.
    DescribeOrganizationalUnitResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeOrganizationalUnitResponse
-> DescribeOrganizationalUnitResponse -> Bool
(DescribeOrganizationalUnitResponse
 -> DescribeOrganizationalUnitResponse -> Bool)
-> (DescribeOrganizationalUnitResponse
    -> DescribeOrganizationalUnitResponse -> Bool)
-> Eq DescribeOrganizationalUnitResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeOrganizationalUnitResponse
-> DescribeOrganizationalUnitResponse -> Bool
$c/= :: DescribeOrganizationalUnitResponse
-> DescribeOrganizationalUnitResponse -> Bool
== :: DescribeOrganizationalUnitResponse
-> DescribeOrganizationalUnitResponse -> Bool
$c== :: DescribeOrganizationalUnitResponse
-> DescribeOrganizationalUnitResponse -> Bool
Prelude.Eq, ReadPrec [DescribeOrganizationalUnitResponse]
ReadPrec DescribeOrganizationalUnitResponse
Int -> ReadS DescribeOrganizationalUnitResponse
ReadS [DescribeOrganizationalUnitResponse]
(Int -> ReadS DescribeOrganizationalUnitResponse)
-> ReadS [DescribeOrganizationalUnitResponse]
-> ReadPrec DescribeOrganizationalUnitResponse
-> ReadPrec [DescribeOrganizationalUnitResponse]
-> Read DescribeOrganizationalUnitResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeOrganizationalUnitResponse]
$creadListPrec :: ReadPrec [DescribeOrganizationalUnitResponse]
readPrec :: ReadPrec DescribeOrganizationalUnitResponse
$creadPrec :: ReadPrec DescribeOrganizationalUnitResponse
readList :: ReadS [DescribeOrganizationalUnitResponse]
$creadList :: ReadS [DescribeOrganizationalUnitResponse]
readsPrec :: Int -> ReadS DescribeOrganizationalUnitResponse
$creadsPrec :: Int -> ReadS DescribeOrganizationalUnitResponse
Prelude.Read, Int -> DescribeOrganizationalUnitResponse -> ShowS
[DescribeOrganizationalUnitResponse] -> ShowS
DescribeOrganizationalUnitResponse -> String
(Int -> DescribeOrganizationalUnitResponse -> ShowS)
-> (DescribeOrganizationalUnitResponse -> String)
-> ([DescribeOrganizationalUnitResponse] -> ShowS)
-> Show DescribeOrganizationalUnitResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeOrganizationalUnitResponse] -> ShowS
$cshowList :: [DescribeOrganizationalUnitResponse] -> ShowS
show :: DescribeOrganizationalUnitResponse -> String
$cshow :: DescribeOrganizationalUnitResponse -> String
showsPrec :: Int -> DescribeOrganizationalUnitResponse -> ShowS
$cshowsPrec :: Int -> DescribeOrganizationalUnitResponse -> ShowS
Prelude.Show, (forall x.
 DescribeOrganizationalUnitResponse
 -> Rep DescribeOrganizationalUnitResponse x)
-> (forall x.
    Rep DescribeOrganizationalUnitResponse x
    -> DescribeOrganizationalUnitResponse)
-> Generic DescribeOrganizationalUnitResponse
forall x.
Rep DescribeOrganizationalUnitResponse x
-> DescribeOrganizationalUnitResponse
forall x.
DescribeOrganizationalUnitResponse
-> Rep DescribeOrganizationalUnitResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeOrganizationalUnitResponse x
-> DescribeOrganizationalUnitResponse
$cfrom :: forall x.
DescribeOrganizationalUnitResponse
-> Rep DescribeOrganizationalUnitResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeOrganizationalUnitResponse' 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:
--
-- 'organizationalUnit', 'describeOrganizationalUnitResponse_organizationalUnit' - A structure that contains details about the specified OU.
--
-- 'httpStatus', 'describeOrganizationalUnitResponse_httpStatus' - The response's http status code.
newDescribeOrganizationalUnitResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeOrganizationalUnitResponse
newDescribeOrganizationalUnitResponse :: Int -> DescribeOrganizationalUnitResponse
newDescribeOrganizationalUnitResponse Int
pHttpStatus_ =
  DescribeOrganizationalUnitResponse' :: Maybe OrganizationalUnit
-> Int -> DescribeOrganizationalUnitResponse
DescribeOrganizationalUnitResponse'
    { $sel:organizationalUnit:DescribeOrganizationalUnitResponse' :: Maybe OrganizationalUnit
organizationalUnit =
        Maybe OrganizationalUnit
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeOrganizationalUnitResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that contains details about the specified OU.
describeOrganizationalUnitResponse_organizationalUnit :: Lens.Lens' DescribeOrganizationalUnitResponse (Prelude.Maybe OrganizationalUnit)
describeOrganizationalUnitResponse_organizationalUnit :: (Maybe OrganizationalUnit -> f (Maybe OrganizationalUnit))
-> DescribeOrganizationalUnitResponse
-> f DescribeOrganizationalUnitResponse
describeOrganizationalUnitResponse_organizationalUnit = (DescribeOrganizationalUnitResponse -> Maybe OrganizationalUnit)
-> (DescribeOrganizationalUnitResponse
    -> Maybe OrganizationalUnit -> DescribeOrganizationalUnitResponse)
-> Lens
     DescribeOrganizationalUnitResponse
     DescribeOrganizationalUnitResponse
     (Maybe OrganizationalUnit)
     (Maybe OrganizationalUnit)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeOrganizationalUnitResponse' {Maybe OrganizationalUnit
organizationalUnit :: Maybe OrganizationalUnit
$sel:organizationalUnit:DescribeOrganizationalUnitResponse' :: DescribeOrganizationalUnitResponse -> Maybe OrganizationalUnit
organizationalUnit} -> Maybe OrganizationalUnit
organizationalUnit) (\s :: DescribeOrganizationalUnitResponse
s@DescribeOrganizationalUnitResponse' {} Maybe OrganizationalUnit
a -> DescribeOrganizationalUnitResponse
s {$sel:organizationalUnit:DescribeOrganizationalUnitResponse' :: Maybe OrganizationalUnit
organizationalUnit = Maybe OrganizationalUnit
a} :: DescribeOrganizationalUnitResponse)

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

instance
  Prelude.NFData
    DescribeOrganizationalUnitResponse