{-# 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.IamActionDefinition
-- 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.IamActionDefinition 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 Identity and Access Management (IAM) action definition details.
--
-- /See:/ 'newIamActionDefinition' smart constructor.
data IamActionDefinition = IamActionDefinition'
  { -- | A list of groups to be attached. There must be at least one group.
    IamActionDefinition -> Maybe (NonEmpty Text)
groups :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | A list of roles to be attached. There must be at least one role.
    IamActionDefinition -> Maybe (NonEmpty Text)
roles :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | A list of users to be attached. There must be at least one user.
    IamActionDefinition -> Maybe (NonEmpty Text)
users :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The Amazon Resource Name (ARN) of the policy to be attached.
    IamActionDefinition -> Text
policyArn :: Prelude.Text
  }
  deriving (IamActionDefinition -> IamActionDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IamActionDefinition -> IamActionDefinition -> Bool
$c/= :: IamActionDefinition -> IamActionDefinition -> Bool
== :: IamActionDefinition -> IamActionDefinition -> Bool
$c== :: IamActionDefinition -> IamActionDefinition -> Bool
Prelude.Eq, ReadPrec [IamActionDefinition]
ReadPrec IamActionDefinition
Int -> ReadS IamActionDefinition
ReadS [IamActionDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IamActionDefinition]
$creadListPrec :: ReadPrec [IamActionDefinition]
readPrec :: ReadPrec IamActionDefinition
$creadPrec :: ReadPrec IamActionDefinition
readList :: ReadS [IamActionDefinition]
$creadList :: ReadS [IamActionDefinition]
readsPrec :: Int -> ReadS IamActionDefinition
$creadsPrec :: Int -> ReadS IamActionDefinition
Prelude.Read, Int -> IamActionDefinition -> ShowS
[IamActionDefinition] -> ShowS
IamActionDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IamActionDefinition] -> ShowS
$cshowList :: [IamActionDefinition] -> ShowS
show :: IamActionDefinition -> String
$cshow :: IamActionDefinition -> String
showsPrec :: Int -> IamActionDefinition -> ShowS
$cshowsPrec :: Int -> IamActionDefinition -> ShowS
Prelude.Show, forall x. Rep IamActionDefinition x -> IamActionDefinition
forall x. IamActionDefinition -> Rep IamActionDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IamActionDefinition x -> IamActionDefinition
$cfrom :: forall x. IamActionDefinition -> Rep IamActionDefinition x
Prelude.Generic)

-- |
-- Create a value of 'IamActionDefinition' 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:
--
-- 'groups', 'iamActionDefinition_groups' - A list of groups to be attached. There must be at least one group.
--
-- 'roles', 'iamActionDefinition_roles' - A list of roles to be attached. There must be at least one role.
--
-- 'users', 'iamActionDefinition_users' - A list of users to be attached. There must be at least one user.
--
-- 'policyArn', 'iamActionDefinition_policyArn' - The Amazon Resource Name (ARN) of the policy to be attached.
newIamActionDefinition ::
  -- | 'policyArn'
  Prelude.Text ->
  IamActionDefinition
newIamActionDefinition :: Text -> IamActionDefinition
newIamActionDefinition Text
pPolicyArn_ =
  IamActionDefinition'
    { $sel:groups:IamActionDefinition' :: Maybe (NonEmpty Text)
groups = forall a. Maybe a
Prelude.Nothing,
      $sel:roles:IamActionDefinition' :: Maybe (NonEmpty Text)
roles = forall a. Maybe a
Prelude.Nothing,
      $sel:users:IamActionDefinition' :: Maybe (NonEmpty Text)
users = forall a. Maybe a
Prelude.Nothing,
      $sel:policyArn:IamActionDefinition' :: Text
policyArn = Text
pPolicyArn_
    }

-- | A list of groups to be attached. There must be at least one group.
iamActionDefinition_groups :: Lens.Lens' IamActionDefinition (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
iamActionDefinition_groups :: Lens' IamActionDefinition (Maybe (NonEmpty Text))
iamActionDefinition_groups = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IamActionDefinition' {Maybe (NonEmpty Text)
groups :: Maybe (NonEmpty Text)
$sel:groups:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
groups} -> Maybe (NonEmpty Text)
groups) (\s :: IamActionDefinition
s@IamActionDefinition' {} Maybe (NonEmpty Text)
a -> IamActionDefinition
s {$sel:groups:IamActionDefinition' :: Maybe (NonEmpty Text)
groups = Maybe (NonEmpty Text)
a} :: IamActionDefinition) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of roles to be attached. There must be at least one role.
iamActionDefinition_roles :: Lens.Lens' IamActionDefinition (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
iamActionDefinition_roles :: Lens' IamActionDefinition (Maybe (NonEmpty Text))
iamActionDefinition_roles = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IamActionDefinition' {Maybe (NonEmpty Text)
roles :: Maybe (NonEmpty Text)
$sel:roles:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
roles} -> Maybe (NonEmpty Text)
roles) (\s :: IamActionDefinition
s@IamActionDefinition' {} Maybe (NonEmpty Text)
a -> IamActionDefinition
s {$sel:roles:IamActionDefinition' :: Maybe (NonEmpty Text)
roles = Maybe (NonEmpty Text)
a} :: IamActionDefinition) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of users to be attached. There must be at least one user.
iamActionDefinition_users :: Lens.Lens' IamActionDefinition (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
iamActionDefinition_users :: Lens' IamActionDefinition (Maybe (NonEmpty Text))
iamActionDefinition_users = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IamActionDefinition' {Maybe (NonEmpty Text)
users :: Maybe (NonEmpty Text)
$sel:users:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
users} -> Maybe (NonEmpty Text)
users) (\s :: IamActionDefinition
s@IamActionDefinition' {} Maybe (NonEmpty Text)
a -> IamActionDefinition
s {$sel:users:IamActionDefinition' :: Maybe (NonEmpty Text)
users = Maybe (NonEmpty Text)
a} :: IamActionDefinition) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Resource Name (ARN) of the policy to be attached.
iamActionDefinition_policyArn :: Lens.Lens' IamActionDefinition Prelude.Text
iamActionDefinition_policyArn :: Lens' IamActionDefinition Text
iamActionDefinition_policyArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IamActionDefinition' {Text
policyArn :: Text
$sel:policyArn:IamActionDefinition' :: IamActionDefinition -> Text
policyArn} -> Text
policyArn) (\s :: IamActionDefinition
s@IamActionDefinition' {} Text
a -> IamActionDefinition
s {$sel:policyArn:IamActionDefinition' :: Text
policyArn = Text
a} :: IamActionDefinition)

instance Data.FromJSON IamActionDefinition where
  parseJSON :: Value -> Parser IamActionDefinition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"IamActionDefinition"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> Text
-> IamActionDefinition
IamActionDefinition'
            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
"Groups")
            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
"Roles")
            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
"Users")
            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
"PolicyArn")
      )

instance Prelude.Hashable IamActionDefinition where
  hashWithSalt :: Int -> IamActionDefinition -> Int
hashWithSalt Int
_salt IamActionDefinition' {Maybe (NonEmpty Text)
Text
policyArn :: Text
users :: Maybe (NonEmpty Text)
roles :: Maybe (NonEmpty Text)
groups :: Maybe (NonEmpty Text)
$sel:policyArn:IamActionDefinition' :: IamActionDefinition -> Text
$sel:users:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
$sel:roles:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
$sel:groups:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
groups
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
roles
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
users
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policyArn

instance Prelude.NFData IamActionDefinition where
  rnf :: IamActionDefinition -> ()
rnf IamActionDefinition' {Maybe (NonEmpty Text)
Text
policyArn :: Text
users :: Maybe (NonEmpty Text)
roles :: Maybe (NonEmpty Text)
groups :: Maybe (NonEmpty Text)
$sel:policyArn:IamActionDefinition' :: IamActionDefinition -> Text
$sel:users:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
$sel:roles:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
$sel:groups:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
groups
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
roles
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
users
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
policyArn

instance Data.ToJSON IamActionDefinition where
  toJSON :: IamActionDefinition -> Value
toJSON IamActionDefinition' {Maybe (NonEmpty Text)
Text
policyArn :: Text
users :: Maybe (NonEmpty Text)
roles :: Maybe (NonEmpty Text)
groups :: Maybe (NonEmpty Text)
$sel:policyArn:IamActionDefinition' :: IamActionDefinition -> Text
$sel:users:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
$sel:roles:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
$sel:groups:IamActionDefinition' :: IamActionDefinition -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Groups" 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 (NonEmpty Text)
groups,
            (Key
"Roles" 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 (NonEmpty Text)
roles,
            (Key
"Users" 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 (NonEmpty Text)
users,
            forall a. a -> Maybe a
Prelude.Just (Key
"PolicyArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
policyArn)
          ]
      )