{-# 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.CodePipeline.Types.ActionTypePermissions
-- 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.CodePipeline.Types.ActionTypePermissions 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

-- | Details identifying the users with permissions to use the action type.
--
-- /See:/ 'newActionTypePermissions' smart constructor.
data ActionTypePermissions = ActionTypePermissions'
  { -- | A list of AWS account IDs with access to use the action type in their
    -- pipelines.
    ActionTypePermissions -> NonEmpty Text
allowedAccounts :: Prelude.NonEmpty Prelude.Text
  }
  deriving (ActionTypePermissions -> ActionTypePermissions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ActionTypePermissions -> ActionTypePermissions -> Bool
$c/= :: ActionTypePermissions -> ActionTypePermissions -> Bool
== :: ActionTypePermissions -> ActionTypePermissions -> Bool
$c== :: ActionTypePermissions -> ActionTypePermissions -> Bool
Prelude.Eq, ReadPrec [ActionTypePermissions]
ReadPrec ActionTypePermissions
Int -> ReadS ActionTypePermissions
ReadS [ActionTypePermissions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ActionTypePermissions]
$creadListPrec :: ReadPrec [ActionTypePermissions]
readPrec :: ReadPrec ActionTypePermissions
$creadPrec :: ReadPrec ActionTypePermissions
readList :: ReadS [ActionTypePermissions]
$creadList :: ReadS [ActionTypePermissions]
readsPrec :: Int -> ReadS ActionTypePermissions
$creadsPrec :: Int -> ReadS ActionTypePermissions
Prelude.Read, Int -> ActionTypePermissions -> ShowS
[ActionTypePermissions] -> ShowS
ActionTypePermissions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ActionTypePermissions] -> ShowS
$cshowList :: [ActionTypePermissions] -> ShowS
show :: ActionTypePermissions -> String
$cshow :: ActionTypePermissions -> String
showsPrec :: Int -> ActionTypePermissions -> ShowS
$cshowsPrec :: Int -> ActionTypePermissions -> ShowS
Prelude.Show, forall x. Rep ActionTypePermissions x -> ActionTypePermissions
forall x. ActionTypePermissions -> Rep ActionTypePermissions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ActionTypePermissions x -> ActionTypePermissions
$cfrom :: forall x. ActionTypePermissions -> Rep ActionTypePermissions x
Prelude.Generic)

-- |
-- Create a value of 'ActionTypePermissions' 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:
--
-- 'allowedAccounts', 'actionTypePermissions_allowedAccounts' - A list of AWS account IDs with access to use the action type in their
-- pipelines.
newActionTypePermissions ::
  -- | 'allowedAccounts'
  Prelude.NonEmpty Prelude.Text ->
  ActionTypePermissions
newActionTypePermissions :: NonEmpty Text -> ActionTypePermissions
newActionTypePermissions NonEmpty Text
pAllowedAccounts_ =
  ActionTypePermissions'
    { $sel:allowedAccounts:ActionTypePermissions' :: NonEmpty Text
allowedAccounts =
        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
pAllowedAccounts_
    }

-- | A list of AWS account IDs with access to use the action type in their
-- pipelines.
actionTypePermissions_allowedAccounts :: Lens.Lens' ActionTypePermissions (Prelude.NonEmpty Prelude.Text)
actionTypePermissions_allowedAccounts :: Lens' ActionTypePermissions (NonEmpty Text)
actionTypePermissions_allowedAccounts = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ActionTypePermissions' {NonEmpty Text
allowedAccounts :: NonEmpty Text
$sel:allowedAccounts:ActionTypePermissions' :: ActionTypePermissions -> NonEmpty Text
allowedAccounts} -> NonEmpty Text
allowedAccounts) (\s :: ActionTypePermissions
s@ActionTypePermissions' {} NonEmpty Text
a -> ActionTypePermissions
s {$sel:allowedAccounts:ActionTypePermissions' :: NonEmpty Text
allowedAccounts = NonEmpty Text
a} :: ActionTypePermissions) 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 ActionTypePermissions where
  parseJSON :: Value -> Parser ActionTypePermissions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ActionTypePermissions"
      ( \Object
x ->
          NonEmpty Text -> ActionTypePermissions
ActionTypePermissions'
            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
"allowedAccounts")
      )

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

instance Prelude.NFData ActionTypePermissions where
  rnf :: ActionTypePermissions -> ()
rnf ActionTypePermissions' {NonEmpty Text
allowedAccounts :: NonEmpty Text
$sel:allowedAccounts:ActionTypePermissions' :: ActionTypePermissions -> NonEmpty Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
allowedAccounts

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