{-# 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.Budgets.Types.ScpActionDefinition
-- 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.Budgets.Types.ScpActionDefinition where

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

-- | The service control policies (SCP) action definition details.
--
-- /See:/ 'newScpActionDefinition' smart constructor.
data ScpActionDefinition = ScpActionDefinition'
  { -- | The policy ID attached.
    ScpActionDefinition -> Text
policyId :: Prelude.Text,
    -- | A list of target IDs.
    ScpActionDefinition -> NonEmpty Text
targetIds :: Prelude.NonEmpty Prelude.Text
  }
  deriving (ScpActionDefinition -> ScpActionDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScpActionDefinition -> ScpActionDefinition -> Bool
$c/= :: ScpActionDefinition -> ScpActionDefinition -> Bool
== :: ScpActionDefinition -> ScpActionDefinition -> Bool
$c== :: ScpActionDefinition -> ScpActionDefinition -> Bool
Prelude.Eq, ReadPrec [ScpActionDefinition]
ReadPrec ScpActionDefinition
Int -> ReadS ScpActionDefinition
ReadS [ScpActionDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ScpActionDefinition]
$creadListPrec :: ReadPrec [ScpActionDefinition]
readPrec :: ReadPrec ScpActionDefinition
$creadPrec :: ReadPrec ScpActionDefinition
readList :: ReadS [ScpActionDefinition]
$creadList :: ReadS [ScpActionDefinition]
readsPrec :: Int -> ReadS ScpActionDefinition
$creadsPrec :: Int -> ReadS ScpActionDefinition
Prelude.Read, Int -> ScpActionDefinition -> ShowS
[ScpActionDefinition] -> ShowS
ScpActionDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScpActionDefinition] -> ShowS
$cshowList :: [ScpActionDefinition] -> ShowS
show :: ScpActionDefinition -> String
$cshow :: ScpActionDefinition -> String
showsPrec :: Int -> ScpActionDefinition -> ShowS
$cshowsPrec :: Int -> ScpActionDefinition -> ShowS
Prelude.Show, forall x. Rep ScpActionDefinition x -> ScpActionDefinition
forall x. ScpActionDefinition -> Rep ScpActionDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ScpActionDefinition x -> ScpActionDefinition
$cfrom :: forall x. ScpActionDefinition -> Rep ScpActionDefinition x
Prelude.Generic)

-- |
-- Create a value of 'ScpActionDefinition' 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:
--
-- 'policyId', 'scpActionDefinition_policyId' - The policy ID attached.
--
-- 'targetIds', 'scpActionDefinition_targetIds' - A list of target IDs.
newScpActionDefinition ::
  -- | 'policyId'
  Prelude.Text ->
  -- | 'targetIds'
  Prelude.NonEmpty Prelude.Text ->
  ScpActionDefinition
newScpActionDefinition :: Text -> NonEmpty Text -> ScpActionDefinition
newScpActionDefinition Text
pPolicyId_ NonEmpty Text
pTargetIds_ =
  ScpActionDefinition'
    { $sel:policyId:ScpActionDefinition' :: Text
policyId = Text
pPolicyId_,
      $sel:targetIds:ScpActionDefinition' :: NonEmpty Text
targetIds = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pTargetIds_
    }

-- | The policy ID attached.
scpActionDefinition_policyId :: Lens.Lens' ScpActionDefinition Prelude.Text
scpActionDefinition_policyId :: Lens' ScpActionDefinition Text
scpActionDefinition_policyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScpActionDefinition' {Text
policyId :: Text
$sel:policyId:ScpActionDefinition' :: ScpActionDefinition -> Text
policyId} -> Text
policyId) (\s :: ScpActionDefinition
s@ScpActionDefinition' {} Text
a -> ScpActionDefinition
s {$sel:policyId:ScpActionDefinition' :: Text
policyId = Text
a} :: ScpActionDefinition)

-- | A list of target IDs.
scpActionDefinition_targetIds :: Lens.Lens' ScpActionDefinition (Prelude.NonEmpty Prelude.Text)
scpActionDefinition_targetIds :: Lens' ScpActionDefinition (NonEmpty Text)
scpActionDefinition_targetIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScpActionDefinition' {NonEmpty Text
targetIds :: NonEmpty Text
$sel:targetIds:ScpActionDefinition' :: ScpActionDefinition -> NonEmpty Text
targetIds} -> NonEmpty Text
targetIds) (\s :: ScpActionDefinition
s@ScpActionDefinition' {} NonEmpty Text
a -> ScpActionDefinition
s {$sel:targetIds:ScpActionDefinition' :: NonEmpty Text
targetIds = NonEmpty Text
a} :: ScpActionDefinition) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON ScpActionDefinition where
  parseJSON :: Value -> Parser ScpActionDefinition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ScpActionDefinition"
      ( \Object
x ->
          Text -> NonEmpty Text -> ScpActionDefinition
ScpActionDefinition'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"PolicyId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"TargetIds")
      )

instance Prelude.Hashable ScpActionDefinition where
  hashWithSalt :: Int -> ScpActionDefinition -> Int
hashWithSalt Int
_salt ScpActionDefinition' {NonEmpty Text
Text
targetIds :: NonEmpty Text
policyId :: Text
$sel:targetIds:ScpActionDefinition' :: ScpActionDefinition -> NonEmpty Text
$sel:policyId:ScpActionDefinition' :: ScpActionDefinition -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
targetIds

instance Prelude.NFData ScpActionDefinition where
  rnf :: ScpActionDefinition -> ()
rnf ScpActionDefinition' {NonEmpty Text
Text
targetIds :: NonEmpty Text
policyId :: Text
$sel:targetIds:ScpActionDefinition' :: ScpActionDefinition -> NonEmpty Text
$sel:policyId:ScpActionDefinition' :: ScpActionDefinition -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
policyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
targetIds

instance Data.ToJSON ScpActionDefinition where
  toJSON :: ScpActionDefinition -> Value
toJSON ScpActionDefinition' {NonEmpty Text
Text
targetIds :: NonEmpty Text
policyId :: Text
$sel:targetIds:ScpActionDefinition' :: ScpActionDefinition -> NonEmpty Text
$sel:policyId:ScpActionDefinition' :: ScpActionDefinition -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"PolicyId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
policyId),
            forall a. a -> Maybe a
Prelude.Just (Key
"TargetIds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
targetIds)
          ]
      )