{-# 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.QuickSight.Types.ResourcePermission
-- 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.QuickSight.Types.ResourcePermission 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

-- | Permission for the resource.
--
-- /See:/ 'newResourcePermission' smart constructor.
data ResourcePermission = ResourcePermission'
  { -- | The Amazon Resource Name (ARN) of the principal. This can be one of the
    -- following:
    --
    -- -   The ARN of an Amazon QuickSight user or group associated with a data
    --     source or dataset. (This is common.)
    --
    -- -   The ARN of an Amazon QuickSight user, group, or namespace associated
    --     with an analysis, dashboard, template, or theme. (This is common.)
    --
    -- -   The ARN of an Amazon Web Services account root: This is an IAM ARN
    --     rather than a QuickSight ARN. Use this option only to share
    --     resources (templates) across Amazon Web Services accounts. (This is
    --     less common.)
    ResourcePermission -> Text
principal :: Prelude.Text,
    -- | The IAM action to grant or revoke permissions on.
    ResourcePermission -> NonEmpty Text
actions :: Prelude.NonEmpty Prelude.Text
  }
  deriving (ResourcePermission -> ResourcePermission -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourcePermission -> ResourcePermission -> Bool
$c/= :: ResourcePermission -> ResourcePermission -> Bool
== :: ResourcePermission -> ResourcePermission -> Bool
$c== :: ResourcePermission -> ResourcePermission -> Bool
Prelude.Eq, ReadPrec [ResourcePermission]
ReadPrec ResourcePermission
Int -> ReadS ResourcePermission
ReadS [ResourcePermission]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourcePermission]
$creadListPrec :: ReadPrec [ResourcePermission]
readPrec :: ReadPrec ResourcePermission
$creadPrec :: ReadPrec ResourcePermission
readList :: ReadS [ResourcePermission]
$creadList :: ReadS [ResourcePermission]
readsPrec :: Int -> ReadS ResourcePermission
$creadsPrec :: Int -> ReadS ResourcePermission
Prelude.Read, Int -> ResourcePermission -> ShowS
[ResourcePermission] -> ShowS
ResourcePermission -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourcePermission] -> ShowS
$cshowList :: [ResourcePermission] -> ShowS
show :: ResourcePermission -> String
$cshow :: ResourcePermission -> String
showsPrec :: Int -> ResourcePermission -> ShowS
$cshowsPrec :: Int -> ResourcePermission -> ShowS
Prelude.Show, forall x. Rep ResourcePermission x -> ResourcePermission
forall x. ResourcePermission -> Rep ResourcePermission x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourcePermission x -> ResourcePermission
$cfrom :: forall x. ResourcePermission -> Rep ResourcePermission x
Prelude.Generic)

-- |
-- Create a value of 'ResourcePermission' 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:
--
-- 'principal', 'resourcePermission_principal' - The Amazon Resource Name (ARN) of the principal. This can be one of the
-- following:
--
-- -   The ARN of an Amazon QuickSight user or group associated with a data
--     source or dataset. (This is common.)
--
-- -   The ARN of an Amazon QuickSight user, group, or namespace associated
--     with an analysis, dashboard, template, or theme. (This is common.)
--
-- -   The ARN of an Amazon Web Services account root: This is an IAM ARN
--     rather than a QuickSight ARN. Use this option only to share
--     resources (templates) across Amazon Web Services accounts. (This is
--     less common.)
--
-- 'actions', 'resourcePermission_actions' - The IAM action to grant or revoke permissions on.
newResourcePermission ::
  -- | 'principal'
  Prelude.Text ->
  -- | 'actions'
  Prelude.NonEmpty Prelude.Text ->
  ResourcePermission
newResourcePermission :: Text -> NonEmpty Text -> ResourcePermission
newResourcePermission Text
pPrincipal_ NonEmpty Text
pActions_ =
  ResourcePermission'
    { $sel:principal:ResourcePermission' :: Text
principal = Text
pPrincipal_,
      $sel:actions:ResourcePermission' :: NonEmpty Text
actions = 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
pActions_
    }

-- | The Amazon Resource Name (ARN) of the principal. This can be one of the
-- following:
--
-- -   The ARN of an Amazon QuickSight user or group associated with a data
--     source or dataset. (This is common.)
--
-- -   The ARN of an Amazon QuickSight user, group, or namespace associated
--     with an analysis, dashboard, template, or theme. (This is common.)
--
-- -   The ARN of an Amazon Web Services account root: This is an IAM ARN
--     rather than a QuickSight ARN. Use this option only to share
--     resources (templates) across Amazon Web Services accounts. (This is
--     less common.)
resourcePermission_principal :: Lens.Lens' ResourcePermission Prelude.Text
resourcePermission_principal :: Lens' ResourcePermission Text
resourcePermission_principal = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePermission' {Text
principal :: Text
$sel:principal:ResourcePermission' :: ResourcePermission -> Text
principal} -> Text
principal) (\s :: ResourcePermission
s@ResourcePermission' {} Text
a -> ResourcePermission
s {$sel:principal:ResourcePermission' :: Text
principal = Text
a} :: ResourcePermission)

-- | The IAM action to grant or revoke permissions on.
resourcePermission_actions :: Lens.Lens' ResourcePermission (Prelude.NonEmpty Prelude.Text)
resourcePermission_actions :: Lens' ResourcePermission (NonEmpty Text)
resourcePermission_actions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePermission' {NonEmpty Text
actions :: NonEmpty Text
$sel:actions:ResourcePermission' :: ResourcePermission -> NonEmpty Text
actions} -> NonEmpty Text
actions) (\s :: ResourcePermission
s@ResourcePermission' {} NonEmpty Text
a -> ResourcePermission
s {$sel:actions:ResourcePermission' :: NonEmpty Text
actions = NonEmpty Text
a} :: ResourcePermission) 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 ResourcePermission where
  parseJSON :: Value -> Parser ResourcePermission
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResourcePermission"
      ( \Object
x ->
          Text -> NonEmpty Text -> ResourcePermission
ResourcePermission'
            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
"Principal")
            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
"Actions")
      )

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

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

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