{-# 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.ColumnLevelPermissionRule
-- 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.ColumnLevelPermissionRule 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

-- | A rule defined to grant access on one or more restricted columns. Each
-- dataset can have multiple rules. To create a restricted column, you add
-- it to one or more rules. Each rule must contain at least one column and
-- at least one user or group. To be able to see a restricted column, a
-- user or group needs to be added to a rule for that column.
--
-- /See:/ 'newColumnLevelPermissionRule' smart constructor.
data ColumnLevelPermissionRule = ColumnLevelPermissionRule'
  { -- | An array of column names.
    ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
columnNames :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | An array of Amazon Resource Names (ARNs) for Amazon QuickSight users or
    -- groups.
    ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
principals :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
$c/= :: ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
== :: ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
$c== :: ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
Prelude.Eq, ReadPrec [ColumnLevelPermissionRule]
ReadPrec ColumnLevelPermissionRule
Int -> ReadS ColumnLevelPermissionRule
ReadS [ColumnLevelPermissionRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ColumnLevelPermissionRule]
$creadListPrec :: ReadPrec [ColumnLevelPermissionRule]
readPrec :: ReadPrec ColumnLevelPermissionRule
$creadPrec :: ReadPrec ColumnLevelPermissionRule
readList :: ReadS [ColumnLevelPermissionRule]
$creadList :: ReadS [ColumnLevelPermissionRule]
readsPrec :: Int -> ReadS ColumnLevelPermissionRule
$creadsPrec :: Int -> ReadS ColumnLevelPermissionRule
Prelude.Read, Int -> ColumnLevelPermissionRule -> ShowS
[ColumnLevelPermissionRule] -> ShowS
ColumnLevelPermissionRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnLevelPermissionRule] -> ShowS
$cshowList :: [ColumnLevelPermissionRule] -> ShowS
show :: ColumnLevelPermissionRule -> String
$cshow :: ColumnLevelPermissionRule -> String
showsPrec :: Int -> ColumnLevelPermissionRule -> ShowS
$cshowsPrec :: Int -> ColumnLevelPermissionRule -> ShowS
Prelude.Show, forall x.
Rep ColumnLevelPermissionRule x -> ColumnLevelPermissionRule
forall x.
ColumnLevelPermissionRule -> Rep ColumnLevelPermissionRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ColumnLevelPermissionRule x -> ColumnLevelPermissionRule
$cfrom :: forall x.
ColumnLevelPermissionRule -> Rep ColumnLevelPermissionRule x
Prelude.Generic)

-- |
-- Create a value of 'ColumnLevelPermissionRule' 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:
--
-- 'columnNames', 'columnLevelPermissionRule_columnNames' - An array of column names.
--
-- 'principals', 'columnLevelPermissionRule_principals' - An array of Amazon Resource Names (ARNs) for Amazon QuickSight users or
-- groups.
newColumnLevelPermissionRule ::
  ColumnLevelPermissionRule
newColumnLevelPermissionRule :: ColumnLevelPermissionRule
newColumnLevelPermissionRule =
  ColumnLevelPermissionRule'
    { $sel:columnNames:ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
columnNames =
        forall a. Maybe a
Prelude.Nothing,
      $sel:principals:ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
principals = forall a. Maybe a
Prelude.Nothing
    }

-- | An array of column names.
columnLevelPermissionRule_columnNames :: Lens.Lens' ColumnLevelPermissionRule (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
columnLevelPermissionRule_columnNames :: Lens' ColumnLevelPermissionRule (Maybe (NonEmpty Text))
columnLevelPermissionRule_columnNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ColumnLevelPermissionRule' {Maybe (NonEmpty Text)
columnNames :: Maybe (NonEmpty Text)
$sel:columnNames:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
columnNames} -> Maybe (NonEmpty Text)
columnNames) (\s :: ColumnLevelPermissionRule
s@ColumnLevelPermissionRule' {} Maybe (NonEmpty Text)
a -> ColumnLevelPermissionRule
s {$sel:columnNames:ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
columnNames = Maybe (NonEmpty Text)
a} :: ColumnLevelPermissionRule) 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

-- | An array of Amazon Resource Names (ARNs) for Amazon QuickSight users or
-- groups.
columnLevelPermissionRule_principals :: Lens.Lens' ColumnLevelPermissionRule (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
columnLevelPermissionRule_principals :: Lens' ColumnLevelPermissionRule (Maybe (NonEmpty Text))
columnLevelPermissionRule_principals = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ColumnLevelPermissionRule' {Maybe (NonEmpty Text)
principals :: Maybe (NonEmpty Text)
$sel:principals:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
principals} -> Maybe (NonEmpty Text)
principals) (\s :: ColumnLevelPermissionRule
s@ColumnLevelPermissionRule' {} Maybe (NonEmpty Text)
a -> ColumnLevelPermissionRule
s {$sel:principals:ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
principals = Maybe (NonEmpty Text)
a} :: ColumnLevelPermissionRule) 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

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

instance Prelude.Hashable ColumnLevelPermissionRule where
  hashWithSalt :: Int -> ColumnLevelPermissionRule -> Int
hashWithSalt Int
_salt ColumnLevelPermissionRule' {Maybe (NonEmpty Text)
principals :: Maybe (NonEmpty Text)
columnNames :: Maybe (NonEmpty Text)
$sel:principals:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
$sel:columnNames:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
columnNames
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
principals

instance Prelude.NFData ColumnLevelPermissionRule where
  rnf :: ColumnLevelPermissionRule -> ()
rnf ColumnLevelPermissionRule' {Maybe (NonEmpty Text)
principals :: Maybe (NonEmpty Text)
columnNames :: Maybe (NonEmpty Text)
$sel:principals:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
$sel:columnNames:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
columnNames
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
principals

instance Data.ToJSON ColumnLevelPermissionRule where
  toJSON :: ColumnLevelPermissionRule -> Value
toJSON ColumnLevelPermissionRule' {Maybe (NonEmpty Text)
principals :: Maybe (NonEmpty Text)
columnNames :: Maybe (NonEmpty Text)
$sel:principals:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
$sel:columnNames:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ColumnNames" 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)
columnNames,
            (Key
"Principals" 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)
principals
          ]
      )