{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 Amazon Web Services performs in the
-- background. Amazon Web Services 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $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 :: Lens' EnablePolicyType Text
enablePolicyType_rootId = 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 :: Lens' EnablePolicyType PolicyType
enablePolicyType_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 :: (Service -> Service)
-> EnablePolicyType -> Request EnablePolicyType
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy EnablePolicyType
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse EnablePolicyType)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Root -> Int -> EnablePolicyTypeResponse
EnablePolicyTypeResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Root")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable EnablePolicyType where
  hashWithSalt :: Int -> EnablePolicyType -> Int
hashWithSalt Int
_salt EnablePolicyType' {Text
PolicyType
policyType :: PolicyType
rootId :: Text
$sel:policyType:EnablePolicyType' :: EnablePolicyType -> PolicyType
$sel:rootId:EnablePolicyType' :: EnablePolicyType -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
rootId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PolicyType
policyType

instance Prelude.NFData EnablePolicyType where
  rnf :: EnablePolicyType -> ()
rnf EnablePolicyType' {Text
PolicyType
policyType :: PolicyType
rootId :: Text
$sel:policyType:EnablePolicyType' :: EnablePolicyType -> PolicyType
$sel:rootId:EnablePolicyType' :: EnablePolicyType -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
rootId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PolicyType
policyType

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"RootId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
rootId),
            forall a. a -> Maybe a
Prelude.Just (Key
"PolicyType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= PolicyType
policyType)
          ]
      )

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

instance Data.ToQuery EnablePolicyType where
  toQuery :: EnablePolicyType -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:root:EnablePolicyTypeResponse' :: Maybe Root
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 :: Lens' EnablePolicyTypeResponse (Maybe Root)
enablePolicyTypeResponse_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 :: Lens' EnablePolicyTypeResponse Int
enablePolicyTypeResponse_httpStatus = 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 where
  rnf :: EnablePolicyTypeResponse -> ()
rnf EnablePolicyTypeResponse' {Int
Maybe Root
httpStatus :: Int
root :: Maybe Root
$sel:httpStatus:EnablePolicyTypeResponse' :: EnablePolicyTypeResponse -> Int
$sel:root:EnablePolicyTypeResponse' :: EnablePolicyTypeResponse -> Maybe Root
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Root
root
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus