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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(ActionTypePermissions -> ActionTypePermissions -> Bool)
-> (ActionTypePermissions -> ActionTypePermissions -> Bool)
-> Eq ActionTypePermissions
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]
(Int -> ReadS ActionTypePermissions)
-> ReadS [ActionTypePermissions]
-> ReadPrec ActionTypePermissions
-> ReadPrec [ActionTypePermissions]
-> Read 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
(Int -> ActionTypePermissions -> ShowS)
-> (ActionTypePermissions -> String)
-> ([ActionTypePermissions] -> ShowS)
-> Show ActionTypePermissions
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. ActionTypePermissions -> Rep ActionTypePermissions x)
-> (forall x. Rep ActionTypePermissions x -> ActionTypePermissions)
-> Generic ActionTypePermissions
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' :: NonEmpty Text -> ActionTypePermissions
ActionTypePermissions'
    { $sel:allowedAccounts:ActionTypePermissions' :: NonEmpty Text
allowedAccounts =
        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
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 :: (NonEmpty Text -> f (NonEmpty Text))
-> ActionTypePermissions -> f ActionTypePermissions
actionTypePermissions_allowedAccounts = (ActionTypePermissions -> NonEmpty Text)
-> (ActionTypePermissions
    -> NonEmpty Text -> ActionTypePermissions)
-> Lens
     ActionTypePermissions
     ActionTypePermissions
     (NonEmpty Text)
     (NonEmpty Text)
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) ((NonEmpty Text -> f (NonEmpty Text))
 -> ActionTypePermissions -> f ActionTypePermissions)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> ActionTypePermissions
-> f ActionTypePermissions
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 ActionTypePermissions where
  parseJSON :: Value -> Parser ActionTypePermissions
parseJSON =
    String
-> (Object -> Parser ActionTypePermissions)
-> Value
-> Parser ActionTypePermissions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ActionTypePermissions"
      ( \Object
x ->
          NonEmpty Text -> ActionTypePermissions
ActionTypePermissions'
            (NonEmpty Text -> ActionTypePermissions)
-> Parser (NonEmpty Text) -> Parser ActionTypePermissions
forall (f :: * -> *) a b. Functor 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
"allowedAccounts")
      )

instance Prelude.Hashable ActionTypePermissions

instance Prelude.NFData ActionTypePermissions

instance Core.ToJSON ActionTypePermissions where
  toJSON :: ActionTypePermissions -> Value
toJSON ActionTypePermissions' {NonEmpty Text
allowedAccounts :: NonEmpty Text
$sel:allowedAccounts:ActionTypePermissions' :: ActionTypePermissions -> NonEmpty 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
"allowedAccounts" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
allowedAccounts)
          ]
      )