{-# 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.LakeFormation.Types.LFTag
-- 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.LakeFormation.Types.LFTag where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A structure that allows an admin to grant user permissions on certain
-- conditions. For example, granting a role access to all columns not
-- tagged \'PII\' of tables tagged \'Prod\'.
--
-- /See:/ 'newLFTag' smart constructor.
data LFTag = LFTag'
  { -- | The key-name for the tag.
    LFTag -> Text
tagKey :: Prelude.Text,
    -- | A list of possible values an attribute can take.
    LFTag -> NonEmpty Text
tagValues :: Prelude.NonEmpty Prelude.Text
  }
  deriving (LFTag -> LFTag -> Bool
(LFTag -> LFTag -> Bool) -> (LFTag -> LFTag -> Bool) -> Eq LFTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LFTag -> LFTag -> Bool
$c/= :: LFTag -> LFTag -> Bool
== :: LFTag -> LFTag -> Bool
$c== :: LFTag -> LFTag -> Bool
Prelude.Eq, ReadPrec [LFTag]
ReadPrec LFTag
Int -> ReadS LFTag
ReadS [LFTag]
(Int -> ReadS LFTag)
-> ReadS [LFTag]
-> ReadPrec LFTag
-> ReadPrec [LFTag]
-> Read LFTag
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LFTag]
$creadListPrec :: ReadPrec [LFTag]
readPrec :: ReadPrec LFTag
$creadPrec :: ReadPrec LFTag
readList :: ReadS [LFTag]
$creadList :: ReadS [LFTag]
readsPrec :: Int -> ReadS LFTag
$creadsPrec :: Int -> ReadS LFTag
Prelude.Read, Int -> LFTag -> ShowS
[LFTag] -> ShowS
LFTag -> String
(Int -> LFTag -> ShowS)
-> (LFTag -> String) -> ([LFTag] -> ShowS) -> Show LFTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LFTag] -> ShowS
$cshowList :: [LFTag] -> ShowS
show :: LFTag -> String
$cshow :: LFTag -> String
showsPrec :: Int -> LFTag -> ShowS
$cshowsPrec :: Int -> LFTag -> ShowS
Prelude.Show, (forall x. LFTag -> Rep LFTag x)
-> (forall x. Rep LFTag x -> LFTag) -> Generic LFTag
forall x. Rep LFTag x -> LFTag
forall x. LFTag -> Rep LFTag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LFTag x -> LFTag
$cfrom :: forall x. LFTag -> Rep LFTag x
Prelude.Generic)

-- |
-- Create a value of 'LFTag' 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:
--
-- 'tagKey', 'lFTag_tagKey' - The key-name for the tag.
--
-- 'tagValues', 'lFTag_tagValues' - A list of possible values an attribute can take.
newLFTag ::
  -- | 'tagKey'
  Prelude.Text ->
  -- | 'tagValues'
  Prelude.NonEmpty Prelude.Text ->
  LFTag
newLFTag :: Text -> NonEmpty Text -> LFTag
newLFTag Text
pTagKey_ NonEmpty Text
pTagValues_ =
  LFTag' :: Text -> NonEmpty Text -> LFTag
LFTag'
    { $sel:tagKey:LFTag' :: Text
tagKey = Text
pTagKey_,
      $sel:tagValues:LFTag' :: NonEmpty Text
tagValues = 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
pTagValues_
    }

-- | The key-name for the tag.
lFTag_tagKey :: Lens.Lens' LFTag Prelude.Text
lFTag_tagKey :: (Text -> f Text) -> LFTag -> f LFTag
lFTag_tagKey = (LFTag -> Text)
-> (LFTag -> Text -> LFTag) -> Lens LFTag LFTag Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LFTag' {Text
tagKey :: Text
$sel:tagKey:LFTag' :: LFTag -> Text
tagKey} -> Text
tagKey) (\s :: LFTag
s@LFTag' {} Text
a -> LFTag
s {$sel:tagKey:LFTag' :: Text
tagKey = Text
a} :: LFTag)

-- | A list of possible values an attribute can take.
lFTag_tagValues :: Lens.Lens' LFTag (Prelude.NonEmpty Prelude.Text)
lFTag_tagValues :: (NonEmpty Text -> f (NonEmpty Text)) -> LFTag -> f LFTag
lFTag_tagValues = (LFTag -> NonEmpty Text)
-> (LFTag -> NonEmpty Text -> LFTag)
-> Lens LFTag LFTag (NonEmpty Text) (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LFTag' {NonEmpty Text
tagValues :: NonEmpty Text
$sel:tagValues:LFTag' :: LFTag -> NonEmpty Text
tagValues} -> NonEmpty Text
tagValues) (\s :: LFTag
s@LFTag' {} NonEmpty Text
a -> LFTag
s {$sel:tagValues:LFTag' :: NonEmpty Text
tagValues = NonEmpty Text
a} :: LFTag) ((NonEmpty Text -> f (NonEmpty Text)) -> LFTag -> f LFTag)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> LFTag
-> f LFTag
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 LFTag where
  parseJSON :: Value -> Parser LFTag
parseJSON =
    String -> (Object -> Parser LFTag) -> Value -> Parser LFTag
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LFTag"
      ( \Object
x ->
          Text -> NonEmpty Text -> LFTag
LFTag'
            (Text -> NonEmpty Text -> LFTag)
-> Parser Text -> Parser (NonEmpty Text -> LFTag)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TagKey")
            Parser (NonEmpty Text -> LFTag)
-> Parser (NonEmpty Text) -> Parser LFTag
forall (f :: * -> *) a b. Applicative f => 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
"TagValues")
      )

instance Prelude.Hashable LFTag

instance Prelude.NFData LFTag

instance Core.ToJSON LFTag where
  toJSON :: LFTag -> Value
toJSON LFTag' {NonEmpty Text
Text
tagValues :: NonEmpty Text
tagKey :: Text
$sel:tagValues:LFTag' :: LFTag -> NonEmpty Text
$sel:tagKey:LFTag' :: LFTag -> 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
"TagKey" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tagKey),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TagValues" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
tagValues)
          ]
      )