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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(ScpActionDefinition -> ScpActionDefinition -> Bool)
-> (ScpActionDefinition -> ScpActionDefinition -> Bool)
-> Eq ScpActionDefinition
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]
(Int -> ReadS ScpActionDefinition)
-> ReadS [ScpActionDefinition]
-> ReadPrec ScpActionDefinition
-> ReadPrec [ScpActionDefinition]
-> Read 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
(Int -> ScpActionDefinition -> ShowS)
-> (ScpActionDefinition -> String)
-> ([ScpActionDefinition] -> ShowS)
-> Show ScpActionDefinition
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. ScpActionDefinition -> Rep ScpActionDefinition x)
-> (forall x. Rep ScpActionDefinition x -> ScpActionDefinition)
-> Generic ScpActionDefinition
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' :: Text -> NonEmpty Text -> ScpActionDefinition
ScpActionDefinition'
    { $sel:policyId:ScpActionDefinition' :: Text
policyId = Text
pPolicyId_,
      $sel:targetIds:ScpActionDefinition' :: NonEmpty Text
targetIds = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
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 :: (Text -> f Text) -> ScpActionDefinition -> f ScpActionDefinition
scpActionDefinition_policyId = (ScpActionDefinition -> Text)
-> (ScpActionDefinition -> Text -> ScpActionDefinition)
-> Lens ScpActionDefinition ScpActionDefinition Text Text
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 :: (NonEmpty Text -> f (NonEmpty Text))
-> ScpActionDefinition -> f ScpActionDefinition
scpActionDefinition_targetIds = (ScpActionDefinition -> NonEmpty Text)
-> (ScpActionDefinition -> NonEmpty Text -> ScpActionDefinition)
-> Lens
     ScpActionDefinition
     ScpActionDefinition
     (NonEmpty Text)
     (NonEmpty Text)
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) ((NonEmpty Text -> f (NonEmpty Text))
 -> ScpActionDefinition -> f ScpActionDefinition)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> ScpActionDefinition
-> f ScpActionDefinition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ScpActionDefinition

instance Prelude.NFData ScpActionDefinition

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PolicyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policyId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TargetIds" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
targetIds)
          ]
      )