{-# 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.DescribeOrganization
-- 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 the organization that the user\'s account
-- belongs to.
--
-- This operation can be called from any account in the organization.
--
-- Even if a policy type is shown as available in the organization, you can
-- disable it separately at the root level with DisablePolicyType. Use
-- ListRoots to see the status of policy types for a specified root.
module Amazonka.Organizations.DescribeOrganization
  ( -- * Creating a Request
    DescribeOrganization (..),
    newDescribeOrganization,

    -- * Destructuring the Response
    DescribeOrganizationResponse (..),
    newDescribeOrganizationResponse,

    -- * Response Lenses
    describeOrganizationResponse_organization,
    describeOrganizationResponse_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:/ 'newDescribeOrganization' smart constructor.
data DescribeOrganization = DescribeOrganization'
  {
  }
  deriving (DescribeOrganization -> DescribeOrganization -> Bool
(DescribeOrganization -> DescribeOrganization -> Bool)
-> (DescribeOrganization -> DescribeOrganization -> Bool)
-> Eq DescribeOrganization
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeOrganization -> DescribeOrganization -> Bool
$c/= :: DescribeOrganization -> DescribeOrganization -> Bool
== :: DescribeOrganization -> DescribeOrganization -> Bool
$c== :: DescribeOrganization -> DescribeOrganization -> Bool
Prelude.Eq, ReadPrec [DescribeOrganization]
ReadPrec DescribeOrganization
Int -> ReadS DescribeOrganization
ReadS [DescribeOrganization]
(Int -> ReadS DescribeOrganization)
-> ReadS [DescribeOrganization]
-> ReadPrec DescribeOrganization
-> ReadPrec [DescribeOrganization]
-> Read DescribeOrganization
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeOrganization]
$creadListPrec :: ReadPrec [DescribeOrganization]
readPrec :: ReadPrec DescribeOrganization
$creadPrec :: ReadPrec DescribeOrganization
readList :: ReadS [DescribeOrganization]
$creadList :: ReadS [DescribeOrganization]
readsPrec :: Int -> ReadS DescribeOrganization
$creadsPrec :: Int -> ReadS DescribeOrganization
Prelude.Read, Int -> DescribeOrganization -> ShowS
[DescribeOrganization] -> ShowS
DescribeOrganization -> String
(Int -> DescribeOrganization -> ShowS)
-> (DescribeOrganization -> String)
-> ([DescribeOrganization] -> ShowS)
-> Show DescribeOrganization
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeOrganization] -> ShowS
$cshowList :: [DescribeOrganization] -> ShowS
show :: DescribeOrganization -> String
$cshow :: DescribeOrganization -> String
showsPrec :: Int -> DescribeOrganization -> ShowS
$cshowsPrec :: Int -> DescribeOrganization -> ShowS
Prelude.Show, (forall x. DescribeOrganization -> Rep DescribeOrganization x)
-> (forall x. Rep DescribeOrganization x -> DescribeOrganization)
-> Generic DescribeOrganization
forall x. Rep DescribeOrganization x -> DescribeOrganization
forall x. DescribeOrganization -> Rep DescribeOrganization x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeOrganization x -> DescribeOrganization
$cfrom :: forall x. DescribeOrganization -> Rep DescribeOrganization x
Prelude.Generic)

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

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

instance Prelude.NFData DescribeOrganization

instance Core.ToHeaders DescribeOrganization where
  toHeaders :: DescribeOrganization -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeOrganization -> 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.DescribeOrganization" ::
                          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 DescribeOrganization where
  toJSON :: DescribeOrganization -> Value
toJSON = Value -> DescribeOrganization -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

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

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

-- | /See:/ 'newDescribeOrganizationResponse' smart constructor.
data DescribeOrganizationResponse = DescribeOrganizationResponse'
  { -- | A structure that contains information about the organization.
    --
    -- The @AvailablePolicyTypes@ part of the response is deprecated, and you
    -- shouldn\'t use it in your apps. It doesn\'t include any policy type
    -- supported by Organizations other than SCPs. To determine which policy
    -- types are enabled in your organization, use the @ ListRoots @ operation.
    DescribeOrganizationResponse -> Maybe Organization
organization :: Prelude.Maybe Organization,
    -- | The response's http status code.
    DescribeOrganizationResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeOrganizationResponse
-> DescribeOrganizationResponse -> Bool
(DescribeOrganizationResponse
 -> DescribeOrganizationResponse -> Bool)
-> (DescribeOrganizationResponse
    -> DescribeOrganizationResponse -> Bool)
-> Eq DescribeOrganizationResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeOrganizationResponse
-> DescribeOrganizationResponse -> Bool
$c/= :: DescribeOrganizationResponse
-> DescribeOrganizationResponse -> Bool
== :: DescribeOrganizationResponse
-> DescribeOrganizationResponse -> Bool
$c== :: DescribeOrganizationResponse
-> DescribeOrganizationResponse -> Bool
Prelude.Eq, Int -> DescribeOrganizationResponse -> ShowS
[DescribeOrganizationResponse] -> ShowS
DescribeOrganizationResponse -> String
(Int -> DescribeOrganizationResponse -> ShowS)
-> (DescribeOrganizationResponse -> String)
-> ([DescribeOrganizationResponse] -> ShowS)
-> Show DescribeOrganizationResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeOrganizationResponse] -> ShowS
$cshowList :: [DescribeOrganizationResponse] -> ShowS
show :: DescribeOrganizationResponse -> String
$cshow :: DescribeOrganizationResponse -> String
showsPrec :: Int -> DescribeOrganizationResponse -> ShowS
$cshowsPrec :: Int -> DescribeOrganizationResponse -> ShowS
Prelude.Show, (forall x.
 DescribeOrganizationResponse -> Rep DescribeOrganizationResponse x)
-> (forall x.
    Rep DescribeOrganizationResponse x -> DescribeOrganizationResponse)
-> Generic DescribeOrganizationResponse
forall x.
Rep DescribeOrganizationResponse x -> DescribeOrganizationResponse
forall x.
DescribeOrganizationResponse -> Rep DescribeOrganizationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeOrganizationResponse x -> DescribeOrganizationResponse
$cfrom :: forall x.
DescribeOrganizationResponse -> Rep DescribeOrganizationResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeOrganizationResponse' 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:
--
-- 'organization', 'describeOrganizationResponse_organization' - A structure that contains information about the organization.
--
-- The @AvailablePolicyTypes@ part of the response is deprecated, and you
-- shouldn\'t use it in your apps. It doesn\'t include any policy type
-- supported by Organizations other than SCPs. To determine which policy
-- types are enabled in your organization, use the @ ListRoots @ operation.
--
-- 'httpStatus', 'describeOrganizationResponse_httpStatus' - The response's http status code.
newDescribeOrganizationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeOrganizationResponse
newDescribeOrganizationResponse :: Int -> DescribeOrganizationResponse
newDescribeOrganizationResponse Int
pHttpStatus_ =
  DescribeOrganizationResponse' :: Maybe Organization -> Int -> DescribeOrganizationResponse
DescribeOrganizationResponse'
    { $sel:organization:DescribeOrganizationResponse' :: Maybe Organization
organization =
        Maybe Organization
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeOrganizationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that contains information about the organization.
--
-- The @AvailablePolicyTypes@ part of the response is deprecated, and you
-- shouldn\'t use it in your apps. It doesn\'t include any policy type
-- supported by Organizations other than SCPs. To determine which policy
-- types are enabled in your organization, use the @ ListRoots @ operation.
describeOrganizationResponse_organization :: Lens.Lens' DescribeOrganizationResponse (Prelude.Maybe Organization)
describeOrganizationResponse_organization :: (Maybe Organization -> f (Maybe Organization))
-> DescribeOrganizationResponse -> f DescribeOrganizationResponse
describeOrganizationResponse_organization = (DescribeOrganizationResponse -> Maybe Organization)
-> (DescribeOrganizationResponse
    -> Maybe Organization -> DescribeOrganizationResponse)
-> Lens
     DescribeOrganizationResponse
     DescribeOrganizationResponse
     (Maybe Organization)
     (Maybe Organization)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeOrganizationResponse' {Maybe Organization
organization :: Maybe Organization
$sel:organization:DescribeOrganizationResponse' :: DescribeOrganizationResponse -> Maybe Organization
organization} -> Maybe Organization
organization) (\s :: DescribeOrganizationResponse
s@DescribeOrganizationResponse' {} Maybe Organization
a -> DescribeOrganizationResponse
s {$sel:organization:DescribeOrganizationResponse' :: Maybe Organization
organization = Maybe Organization
a} :: DescribeOrganizationResponse)

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

instance Prelude.NFData DescribeOrganizationResponse