{-# 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.EnablePolicyType
-- 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)
--
-- Enables a policy type in a root. After you enable a policy type in a
-- root, you can attach policies of that type to the root, any
-- organizational unit (OU), or account in that root. You can undo this by
-- using the DisablePolicyType operation.
--
-- This is an asynchronous request that AWS performs in the background. AWS
-- recommends that you first use ListRoots to see the status of policy
-- types for a specified root, and then use this operation.
--
-- This operation can be called only from the organization\'s management
-- account.
--
-- You can enable a policy type in a root only if that policy type is
-- available in the organization. To view the status of available policy
-- types in the organization, use DescribeOrganization.
module Amazonka.Organizations.EnablePolicyType
  ( -- * Creating a Request
    EnablePolicyType (..),
    newEnablePolicyType,

    -- * Request Lenses
    enablePolicyType_rootId,
    enablePolicyType_policyType,

    -- * Destructuring the Response
    EnablePolicyTypeResponse (..),
    newEnablePolicyTypeResponse,

    -- * Response Lenses
    enablePolicyTypeResponse_root,
    enablePolicyTypeResponse_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:/ 'newEnablePolicyType' smart constructor.
data EnablePolicyType = EnablePolicyType'
  { -- | The unique identifier (ID) of the root in which you want to enable a
    -- policy type. You can get the ID from the ListRoots operation.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> for a root ID string
    -- requires \"r-\" followed by from 4 to 32 lowercase letters or digits.
    EnablePolicyType -> Text
rootId :: Prelude.Text,
    -- | The policy type that you want to enable. You can specify one of the
    -- following values:
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
    --
    -- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
    EnablePolicyType -> PolicyType
policyType :: PolicyType
  }
  deriving (EnablePolicyType -> EnablePolicyType -> Bool
(EnablePolicyType -> EnablePolicyType -> Bool)
-> (EnablePolicyType -> EnablePolicyType -> Bool)
-> Eq EnablePolicyType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnablePolicyType -> EnablePolicyType -> Bool
$c/= :: EnablePolicyType -> EnablePolicyType -> Bool
== :: EnablePolicyType -> EnablePolicyType -> Bool
$c== :: EnablePolicyType -> EnablePolicyType -> Bool
Prelude.Eq, ReadPrec [EnablePolicyType]
ReadPrec EnablePolicyType
Int -> ReadS EnablePolicyType
ReadS [EnablePolicyType]
(Int -> ReadS EnablePolicyType)
-> ReadS [EnablePolicyType]
-> ReadPrec EnablePolicyType
-> ReadPrec [EnablePolicyType]
-> Read EnablePolicyType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnablePolicyType]
$creadListPrec :: ReadPrec [EnablePolicyType]
readPrec :: ReadPrec EnablePolicyType
$creadPrec :: ReadPrec EnablePolicyType
readList :: ReadS [EnablePolicyType]
$creadList :: ReadS [EnablePolicyType]
readsPrec :: Int -> ReadS EnablePolicyType
$creadsPrec :: Int -> ReadS EnablePolicyType
Prelude.Read, Int -> EnablePolicyType -> ShowS
[EnablePolicyType] -> ShowS
EnablePolicyType -> String
(Int -> EnablePolicyType -> ShowS)
-> (EnablePolicyType -> String)
-> ([EnablePolicyType] -> ShowS)
-> Show EnablePolicyType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnablePolicyType] -> ShowS
$cshowList :: [EnablePolicyType] -> ShowS
show :: EnablePolicyType -> String
$cshow :: EnablePolicyType -> String
showsPrec :: Int -> EnablePolicyType -> ShowS
$cshowsPrec :: Int -> EnablePolicyType -> ShowS
Prelude.Show, (forall x. EnablePolicyType -> Rep EnablePolicyType x)
-> (forall x. Rep EnablePolicyType x -> EnablePolicyType)
-> Generic EnablePolicyType
forall x. Rep EnablePolicyType x -> EnablePolicyType
forall x. EnablePolicyType -> Rep EnablePolicyType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnablePolicyType x -> EnablePolicyType
$cfrom :: forall x. EnablePolicyType -> Rep EnablePolicyType x
Prelude.Generic)

-- |
-- Create a value of 'EnablePolicyType' 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:
--
-- 'rootId', 'enablePolicyType_rootId' - The unique identifier (ID) of the root in which you want to enable a
-- policy type. You can get the ID from the ListRoots operation.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a root ID string
-- requires \"r-\" followed by from 4 to 32 lowercase letters or digits.
--
-- 'policyType', 'enablePolicyType_policyType' - The policy type that you want to enable. You can specify one of the
-- following values:
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
newEnablePolicyType ::
  -- | 'rootId'
  Prelude.Text ->
  -- | 'policyType'
  PolicyType ->
  EnablePolicyType
newEnablePolicyType :: Text -> PolicyType -> EnablePolicyType
newEnablePolicyType Text
pRootId_ PolicyType
pPolicyType_ =
  EnablePolicyType' :: Text -> PolicyType -> EnablePolicyType
EnablePolicyType'
    { $sel:rootId:EnablePolicyType' :: Text
rootId = Text
pRootId_,
      $sel:policyType:EnablePolicyType' :: PolicyType
policyType = PolicyType
pPolicyType_
    }

-- | The unique identifier (ID) of the root in which you want to enable a
-- policy type. You can get the ID from the ListRoots operation.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> for a root ID string
-- requires \"r-\" followed by from 4 to 32 lowercase letters or digits.
enablePolicyType_rootId :: Lens.Lens' EnablePolicyType Prelude.Text
enablePolicyType_rootId :: (Text -> f Text) -> EnablePolicyType -> f EnablePolicyType
enablePolicyType_rootId = (EnablePolicyType -> Text)
-> (EnablePolicyType -> Text -> EnablePolicyType)
-> Lens EnablePolicyType EnablePolicyType Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnablePolicyType' {Text
rootId :: Text
$sel:rootId:EnablePolicyType' :: EnablePolicyType -> Text
rootId} -> Text
rootId) (\s :: EnablePolicyType
s@EnablePolicyType' {} Text
a -> EnablePolicyType
s {$sel:rootId:EnablePolicyType' :: Text
rootId = Text
a} :: EnablePolicyType)

-- | The policy type that you want to enable. You can specify one of the
-- following values:
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_ai-opt-out.html AISERVICES_OPT_OUT_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_backup.html BACKUP_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp.html SERVICE_CONTROL_POLICY>
--
-- -   <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html TAG_POLICY>
enablePolicyType_policyType :: Lens.Lens' EnablePolicyType PolicyType
enablePolicyType_policyType :: (PolicyType -> f PolicyType)
-> EnablePolicyType -> f EnablePolicyType
enablePolicyType_policyType = (EnablePolicyType -> PolicyType)
-> (EnablePolicyType -> PolicyType -> EnablePolicyType)
-> Lens EnablePolicyType EnablePolicyType PolicyType PolicyType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnablePolicyType' {PolicyType
policyType :: PolicyType
$sel:policyType:EnablePolicyType' :: EnablePolicyType -> PolicyType
policyType} -> PolicyType
policyType) (\s :: EnablePolicyType
s@EnablePolicyType' {} PolicyType
a -> EnablePolicyType
s {$sel:policyType:EnablePolicyType' :: PolicyType
policyType = PolicyType
a} :: EnablePolicyType)

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

instance Prelude.NFData EnablePolicyType

instance Core.ToHeaders EnablePolicyType where
  toHeaders :: EnablePolicyType -> ResponseHeaders
toHeaders =
    ResponseHeaders -> EnablePolicyType -> 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.EnablePolicyType" ::
                          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 EnablePolicyType where
  toJSON :: EnablePolicyType -> Value
toJSON EnablePolicyType' {Text
PolicyType
policyType :: PolicyType
rootId :: Text
$sel:policyType:EnablePolicyType' :: EnablePolicyType -> PolicyType
$sel:rootId:EnablePolicyType' :: EnablePolicyType -> 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
"RootId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
rootId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PolicyType" Text -> PolicyType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PolicyType
policyType)
          ]
      )

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

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

-- | /See:/ 'newEnablePolicyTypeResponse' smart constructor.
data EnablePolicyTypeResponse = EnablePolicyTypeResponse'
  { -- | A structure that shows the root with the updated list of enabled policy
    -- types.
    EnablePolicyTypeResponse -> Maybe Root
root :: Prelude.Maybe Root,
    -- | The response's http status code.
    EnablePolicyTypeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (EnablePolicyTypeResponse -> EnablePolicyTypeResponse -> Bool
(EnablePolicyTypeResponse -> EnablePolicyTypeResponse -> Bool)
-> (EnablePolicyTypeResponse -> EnablePolicyTypeResponse -> Bool)
-> Eq EnablePolicyTypeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnablePolicyTypeResponse -> EnablePolicyTypeResponse -> Bool
$c/= :: EnablePolicyTypeResponse -> EnablePolicyTypeResponse -> Bool
== :: EnablePolicyTypeResponse -> EnablePolicyTypeResponse -> Bool
$c== :: EnablePolicyTypeResponse -> EnablePolicyTypeResponse -> Bool
Prelude.Eq, ReadPrec [EnablePolicyTypeResponse]
ReadPrec EnablePolicyTypeResponse
Int -> ReadS EnablePolicyTypeResponse
ReadS [EnablePolicyTypeResponse]
(Int -> ReadS EnablePolicyTypeResponse)
-> ReadS [EnablePolicyTypeResponse]
-> ReadPrec EnablePolicyTypeResponse
-> ReadPrec [EnablePolicyTypeResponse]
-> Read EnablePolicyTypeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnablePolicyTypeResponse]
$creadListPrec :: ReadPrec [EnablePolicyTypeResponse]
readPrec :: ReadPrec EnablePolicyTypeResponse
$creadPrec :: ReadPrec EnablePolicyTypeResponse
readList :: ReadS [EnablePolicyTypeResponse]
$creadList :: ReadS [EnablePolicyTypeResponse]
readsPrec :: Int -> ReadS EnablePolicyTypeResponse
$creadsPrec :: Int -> ReadS EnablePolicyTypeResponse
Prelude.Read, Int -> EnablePolicyTypeResponse -> ShowS
[EnablePolicyTypeResponse] -> ShowS
EnablePolicyTypeResponse -> String
(Int -> EnablePolicyTypeResponse -> ShowS)
-> (EnablePolicyTypeResponse -> String)
-> ([EnablePolicyTypeResponse] -> ShowS)
-> Show EnablePolicyTypeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnablePolicyTypeResponse] -> ShowS
$cshowList :: [EnablePolicyTypeResponse] -> ShowS
show :: EnablePolicyTypeResponse -> String
$cshow :: EnablePolicyTypeResponse -> String
showsPrec :: Int -> EnablePolicyTypeResponse -> ShowS
$cshowsPrec :: Int -> EnablePolicyTypeResponse -> ShowS
Prelude.Show, (forall x.
 EnablePolicyTypeResponse -> Rep EnablePolicyTypeResponse x)
-> (forall x.
    Rep EnablePolicyTypeResponse x -> EnablePolicyTypeResponse)
-> Generic EnablePolicyTypeResponse
forall x.
Rep EnablePolicyTypeResponse x -> EnablePolicyTypeResponse
forall x.
EnablePolicyTypeResponse -> Rep EnablePolicyTypeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep EnablePolicyTypeResponse x -> EnablePolicyTypeResponse
$cfrom :: forall x.
EnablePolicyTypeResponse -> Rep EnablePolicyTypeResponse x
Prelude.Generic)

-- |
-- Create a value of 'EnablePolicyTypeResponse' 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:
--
-- 'root', 'enablePolicyTypeResponse_root' - A structure that shows the root with the updated list of enabled policy
-- types.
--
-- 'httpStatus', 'enablePolicyTypeResponse_httpStatus' - The response's http status code.
newEnablePolicyTypeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  EnablePolicyTypeResponse
newEnablePolicyTypeResponse :: Int -> EnablePolicyTypeResponse
newEnablePolicyTypeResponse Int
pHttpStatus_ =
  EnablePolicyTypeResponse' :: Maybe Root -> Int -> EnablePolicyTypeResponse
EnablePolicyTypeResponse'
    { $sel:root:EnablePolicyTypeResponse' :: Maybe Root
root = Maybe Root
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:EnablePolicyTypeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A structure that shows the root with the updated list of enabled policy
-- types.
enablePolicyTypeResponse_root :: Lens.Lens' EnablePolicyTypeResponse (Prelude.Maybe Root)
enablePolicyTypeResponse_root :: (Maybe Root -> f (Maybe Root))
-> EnablePolicyTypeResponse -> f EnablePolicyTypeResponse
enablePolicyTypeResponse_root = (EnablePolicyTypeResponse -> Maybe Root)
-> (EnablePolicyTypeResponse
    -> Maybe Root -> EnablePolicyTypeResponse)
-> Lens
     EnablePolicyTypeResponse
     EnablePolicyTypeResponse
     (Maybe Root)
     (Maybe Root)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnablePolicyTypeResponse' {Maybe Root
root :: Maybe Root
$sel:root:EnablePolicyTypeResponse' :: EnablePolicyTypeResponse -> Maybe Root
root} -> Maybe Root
root) (\s :: EnablePolicyTypeResponse
s@EnablePolicyTypeResponse' {} Maybe Root
a -> EnablePolicyTypeResponse
s {$sel:root:EnablePolicyTypeResponse' :: Maybe Root
root = Maybe Root
a} :: EnablePolicyTypeResponse)

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

instance Prelude.NFData EnablePolicyTypeResponse