{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ComputeOptimizer.Types.Scope
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ComputeOptimizer.Types.Scope where

import Amazonka.ComputeOptimizer.Types.ScopeName
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Describes the scope of a recommendation preference.
--
-- Recommendation preferences can be created at the organization level (for
-- management accounts of an organization only), account level, and
-- resource level. For more information, see
-- <https://docs.aws.amazon.com/compute-optimizer/latest/ug/enhanced-infrastructure-metrics.html Activating enhanced infrastructure metrics>
-- in the /Compute Optimizer User Guide/.
--
-- You cannot create recommendation preferences for Auto Scaling groups at
-- the organization and account levels. You can create recommendation
-- preferences for Auto Scaling groups only at the resource level by
-- specifying a scope name of @ResourceArn@ and a scope value of the Auto
-- Scaling group Amazon Resource Name (ARN). This will configure the
-- preference for all instances that are part of the specified Auto Scaling
-- group. You also cannot create recommendation preferences at the resource
-- level for instances that are part of an Auto Scaling group. You can
-- create recommendation preferences at the resource level only for
-- standalone instances.
--
-- /See:/ 'newScope' smart constructor.
data Scope = Scope'
  { -- | The name of the scope.
    --
    -- The following scopes are possible:
    --
    -- -   @Organization@ - Specifies that the recommendation preference
    --     applies at the organization level, for all member accounts of an
    --     organization.
    --
    -- -   @AccountId@ - Specifies that the recommendation preference applies
    --     at the account level, for all resources of a given resource type in
    --     an account.
    --
    -- -   @ResourceArn@ - Specifies that the recommendation preference applies
    --     at the individual resource level.
    Scope -> Maybe ScopeName
name :: Prelude.Maybe ScopeName,
    -- | The value of the scope.
    --
    -- If you specified the @name@ of the scope as:
    --
    -- -   @Organization@ - The @value@ must be @ALL_ACCOUNTS@.
    --
    -- -   @AccountId@ - The @value@ must be a 12-digit Amazon Web Services
    --     account ID.
    --
    -- -   @ResourceArn@ - The @value@ must be the Amazon Resource Name (ARN)
    --     of an EC2 instance or an Auto Scaling group.
    --
    -- Only EC2 instance and Auto Scaling group ARNs are currently supported.
    Scope -> Maybe Text
value :: Prelude.Maybe Prelude.Text
  }
  deriving (Scope -> Scope -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Scope -> Scope -> Bool
$c/= :: Scope -> Scope -> Bool
== :: Scope -> Scope -> Bool
$c== :: Scope -> Scope -> Bool
Prelude.Eq, ReadPrec [Scope]
ReadPrec Scope
Int -> ReadS Scope
ReadS [Scope]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Scope]
$creadListPrec :: ReadPrec [Scope]
readPrec :: ReadPrec Scope
$creadPrec :: ReadPrec Scope
readList :: ReadS [Scope]
$creadList :: ReadS [Scope]
readsPrec :: Int -> ReadS Scope
$creadsPrec :: Int -> ReadS Scope
Prelude.Read, Int -> Scope -> ShowS
[Scope] -> ShowS
Scope -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Scope] -> ShowS
$cshowList :: [Scope] -> ShowS
show :: Scope -> String
$cshow :: Scope -> String
showsPrec :: Int -> Scope -> ShowS
$cshowsPrec :: Int -> Scope -> ShowS
Prelude.Show, forall x. Rep Scope x -> Scope
forall x. Scope -> Rep Scope x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Scope x -> Scope
$cfrom :: forall x. Scope -> Rep Scope x
Prelude.Generic)

-- |
-- Create a value of 'Scope' 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:
--
-- 'name', 'scope_name' - The name of the scope.
--
-- The following scopes are possible:
--
-- -   @Organization@ - Specifies that the recommendation preference
--     applies at the organization level, for all member accounts of an
--     organization.
--
-- -   @AccountId@ - Specifies that the recommendation preference applies
--     at the account level, for all resources of a given resource type in
--     an account.
--
-- -   @ResourceArn@ - Specifies that the recommendation preference applies
--     at the individual resource level.
--
-- 'value', 'scope_value' - The value of the scope.
--
-- If you specified the @name@ of the scope as:
--
-- -   @Organization@ - The @value@ must be @ALL_ACCOUNTS@.
--
-- -   @AccountId@ - The @value@ must be a 12-digit Amazon Web Services
--     account ID.
--
-- -   @ResourceArn@ - The @value@ must be the Amazon Resource Name (ARN)
--     of an EC2 instance or an Auto Scaling group.
--
-- Only EC2 instance and Auto Scaling group ARNs are currently supported.
newScope ::
  Scope
newScope :: Scope
newScope =
  Scope'
    { $sel:name:Scope' :: Maybe ScopeName
name = forall a. Maybe a
Prelude.Nothing,
      $sel:value:Scope' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the scope.
--
-- The following scopes are possible:
--
-- -   @Organization@ - Specifies that the recommendation preference
--     applies at the organization level, for all member accounts of an
--     organization.
--
-- -   @AccountId@ - Specifies that the recommendation preference applies
--     at the account level, for all resources of a given resource type in
--     an account.
--
-- -   @ResourceArn@ - Specifies that the recommendation preference applies
--     at the individual resource level.
scope_name :: Lens.Lens' Scope (Prelude.Maybe ScopeName)
scope_name :: Lens' Scope (Maybe ScopeName)
scope_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Scope' {Maybe ScopeName
name :: Maybe ScopeName
$sel:name:Scope' :: Scope -> Maybe ScopeName
name} -> Maybe ScopeName
name) (\s :: Scope
s@Scope' {} Maybe ScopeName
a -> Scope
s {$sel:name:Scope' :: Maybe ScopeName
name = Maybe ScopeName
a} :: Scope)

-- | The value of the scope.
--
-- If you specified the @name@ of the scope as:
--
-- -   @Organization@ - The @value@ must be @ALL_ACCOUNTS@.
--
-- -   @AccountId@ - The @value@ must be a 12-digit Amazon Web Services
--     account ID.
--
-- -   @ResourceArn@ - The @value@ must be the Amazon Resource Name (ARN)
--     of an EC2 instance or an Auto Scaling group.
--
-- Only EC2 instance and Auto Scaling group ARNs are currently supported.
scope_value :: Lens.Lens' Scope (Prelude.Maybe Prelude.Text)
scope_value :: Lens' Scope (Maybe Text)
scope_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Scope' {Maybe Text
value :: Maybe Text
$sel:value:Scope' :: Scope -> Maybe Text
value} -> Maybe Text
value) (\s :: Scope
s@Scope' {} Maybe Text
a -> Scope
s {$sel:value:Scope' :: Maybe Text
value = Maybe Text
a} :: Scope)

instance Data.FromJSON Scope where
  parseJSON :: Value -> Parser Scope
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Scope"
      ( \Object
x ->
          Maybe ScopeName -> Maybe Text -> Scope
Scope'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"value")
      )

instance Prelude.Hashable Scope where
  hashWithSalt :: Int -> Scope -> Int
hashWithSalt Int
_salt Scope' {Maybe Text
Maybe ScopeName
value :: Maybe Text
name :: Maybe ScopeName
$sel:value:Scope' :: Scope -> Maybe Text
$sel:name:Scope' :: Scope -> Maybe ScopeName
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ScopeName
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

instance Prelude.NFData Scope where
  rnf :: Scope -> ()
rnf Scope' {Maybe Text
Maybe ScopeName
value :: Maybe Text
name :: Maybe ScopeName
$sel:value:Scope' :: Scope -> Maybe Text
$sel:name:Scope' :: Scope -> Maybe ScopeName
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ScopeName
name seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value

instance Data.ToJSON Scope where
  toJSON :: Scope -> Value
toJSON Scope' {Maybe Text
Maybe ScopeName
value :: Maybe Text
name :: Maybe ScopeName
$sel:value:Scope' :: Scope -> Maybe Text
$sel:name:Scope' :: Scope -> Maybe ScopeName
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ScopeName
name,
            (Key
"value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value
          ]
      )