{-# 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.DisablePolicyType
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Disables an organizational policy type in a root. A policy of a certain
-- type can be attached to entities in a root only if that type is enabled
-- in the root. After you perform this operation, you no longer can attach
-- policies of the specified type to that root or to any organizational
-- unit (OU) or account in that root. You can undo this by using the
-- EnablePolicyType operation.
--
-- This is an asynchronous request that Amazon Web Services performs in the
-- background. If you disable a policy type for a root, it still appears
-- enabled for the organization if
-- <https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_support-all-features.html all features>
-- are enabled for the organization. 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.
--
-- To view the status of available policy types in the organization, use
-- DescribeOrganization.
module Amazonka.Organizations.DisablePolicyType
  ( -- * Creating a Request
    DisablePolicyType (..),
    newDisablePolicyType,

    -- * Request Lenses
    disablePolicyType_rootId,
    disablePolicyType_policyType,

    -- * Destructuring the Response
    DisablePolicyTypeResponse (..),
    newDisablePolicyTypeResponse,

    -- * Response Lenses
    disablePolicyTypeResponse_root,
    disablePolicyTypeResponse_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:/ 'newDisablePolicyType' smart constructor.
data DisablePolicyType = DisablePolicyType'
  { -- | The unique identifier (ID) of the root in which you want to disable 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.
    DisablePolicyType -> Text
rootId :: Prelude.Text,
    -- | The policy type that you want to disable in this root. 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>
    DisablePolicyType -> PolicyType
policyType :: PolicyType
  }
  deriving (DisablePolicyType -> DisablePolicyType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DisablePolicyType -> DisablePolicyType -> Bool
$c/= :: DisablePolicyType -> DisablePolicyType -> Bool
== :: DisablePolicyType -> DisablePolicyType -> Bool
$c== :: DisablePolicyType -> DisablePolicyType -> Bool
Prelude.Eq, ReadPrec [DisablePolicyType]
ReadPrec DisablePolicyType
Int -> ReadS DisablePolicyType
ReadS [DisablePolicyType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DisablePolicyType]
$creadListPrec :: ReadPrec [DisablePolicyType]
readPrec :: ReadPrec DisablePolicyType
$creadPrec :: ReadPrec DisablePolicyType
readList :: ReadS [DisablePolicyType]
$creadList :: ReadS [DisablePolicyType]
readsPrec :: Int -> ReadS DisablePolicyType
$creadsPrec :: Int -> ReadS DisablePolicyType
Prelude.Read, Int -> DisablePolicyType -> ShowS
[DisablePolicyType] -> ShowS
DisablePolicyType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DisablePolicyType] -> ShowS
$cshowList :: [DisablePolicyType] -> ShowS
show :: DisablePolicyType -> String
$cshow :: DisablePolicyType -> String
showsPrec :: Int -> DisablePolicyType -> ShowS
$cshowsPrec :: Int -> DisablePolicyType -> ShowS
Prelude.Show, forall x. Rep DisablePolicyType x -> DisablePolicyType
forall x. DisablePolicyType -> Rep DisablePolicyType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DisablePolicyType x -> DisablePolicyType
$cfrom :: forall x. DisablePolicyType -> Rep DisablePolicyType x
Prelude.Generic)

-- |
-- Create a value of 'DisablePolicyType' 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', 'disablePolicyType_rootId' - The unique identifier (ID) of the root in which you want to disable 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', 'disablePolicyType_policyType' - The policy type that you want to disable in this root. 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>
newDisablePolicyType ::
  -- | 'rootId'
  Prelude.Text ->
  -- | 'policyType'
  PolicyType ->
  DisablePolicyType
newDisablePolicyType :: Text -> PolicyType -> DisablePolicyType
newDisablePolicyType Text
pRootId_ PolicyType
pPolicyType_ =
  DisablePolicyType'
    { $sel:rootId:DisablePolicyType' :: Text
rootId = Text
pRootId_,
      $sel:policyType:DisablePolicyType' :: PolicyType
policyType = PolicyType
pPolicyType_
    }

-- | The unique identifier (ID) of the root in which you want to disable 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.
disablePolicyType_rootId :: Lens.Lens' DisablePolicyType Prelude.Text
disablePolicyType_rootId :: Lens' DisablePolicyType Text
disablePolicyType_rootId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisablePolicyType' {Text
rootId :: Text
$sel:rootId:DisablePolicyType' :: DisablePolicyType -> Text
rootId} -> Text
rootId) (\s :: DisablePolicyType
s@DisablePolicyType' {} Text
a -> DisablePolicyType
s {$sel:rootId:DisablePolicyType' :: Text
rootId = Text
a} :: DisablePolicyType)

-- | The policy type that you want to disable in this root. 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>
disablePolicyType_policyType :: Lens.Lens' DisablePolicyType PolicyType
disablePolicyType_policyType :: Lens' DisablePolicyType PolicyType
disablePolicyType_policyType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DisablePolicyType' {PolicyType
policyType :: PolicyType
$sel:policyType:DisablePolicyType' :: DisablePolicyType -> PolicyType
policyType} -> PolicyType
policyType) (\s :: DisablePolicyType
s@DisablePolicyType' {} PolicyType
a -> DisablePolicyType
s {$sel:policyType:DisablePolicyType' :: PolicyType
policyType = PolicyType
a} :: DisablePolicyType)

instance Core.AWSRequest DisablePolicyType where
  type
    AWSResponse DisablePolicyType =
      DisablePolicyTypeResponse
  request :: (Service -> Service)
-> DisablePolicyType -> Request DisablePolicyType
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 DisablePolicyType
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DisablePolicyType)))
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 -> DisablePolicyTypeResponse
DisablePolicyTypeResponse'
            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 DisablePolicyType where
  hashWithSalt :: Int -> DisablePolicyType -> Int
hashWithSalt Int
_salt DisablePolicyType' {Text
PolicyType
policyType :: PolicyType
rootId :: Text
$sel:policyType:DisablePolicyType' :: DisablePolicyType -> PolicyType
$sel:rootId:DisablePolicyType' :: DisablePolicyType -> 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 DisablePolicyType where
  rnf :: DisablePolicyType -> ()
rnf DisablePolicyType' {Text
PolicyType
policyType :: PolicyType
rootId :: Text
$sel:policyType:DisablePolicyType' :: DisablePolicyType -> PolicyType
$sel:rootId:DisablePolicyType' :: DisablePolicyType -> 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 DisablePolicyType where
  toHeaders :: DisablePolicyType -> 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.DisablePolicyType" ::
                          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 DisablePolicyType where
  toJSON :: DisablePolicyType -> Value
toJSON DisablePolicyType' {Text
PolicyType
policyType :: PolicyType
rootId :: Text
$sel:policyType:DisablePolicyType' :: DisablePolicyType -> PolicyType
$sel:rootId:DisablePolicyType' :: DisablePolicyType -> 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 DisablePolicyType where
  toPath :: DisablePolicyType -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

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

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

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

instance Prelude.NFData DisablePolicyTypeResponse where
  rnf :: DisablePolicyTypeResponse -> ()
rnf DisablePolicyTypeResponse' {Int
Maybe Root
httpStatus :: Int
root :: Maybe Root
$sel:httpStatus:DisablePolicyTypeResponse' :: DisablePolicyTypeResponse -> Int
$sel:root:DisablePolicyTypeResponse' :: DisablePolicyTypeResponse -> 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