{-# 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.LFTagPair
-- 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.LFTagPair where

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

-- | A structure containing a tag key-value pair.
--
-- /See:/ 'newLFTagPair' smart constructor.
data LFTagPair = LFTagPair'
  { -- | The identifier for the Data Catalog. By default, the account ID. The
    -- Data Catalog is the persistent metadata store. It contains database
    -- definitions, table definitions, and other control information to manage
    -- your AWS Lake Formation environment.
    LFTagPair -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The key-name for the tag.
    LFTagPair -> Text
tagKey :: Prelude.Text,
    -- | A list of possible values an attribute can take.
    LFTagPair -> NonEmpty Text
tagValues :: Prelude.NonEmpty Prelude.Text
  }
  deriving (LFTagPair -> LFTagPair -> Bool
(LFTagPair -> LFTagPair -> Bool)
-> (LFTagPair -> LFTagPair -> Bool) -> Eq LFTagPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LFTagPair -> LFTagPair -> Bool
$c/= :: LFTagPair -> LFTagPair -> Bool
== :: LFTagPair -> LFTagPair -> Bool
$c== :: LFTagPair -> LFTagPair -> Bool
Prelude.Eq, ReadPrec [LFTagPair]
ReadPrec LFTagPair
Int -> ReadS LFTagPair
ReadS [LFTagPair]
(Int -> ReadS LFTagPair)
-> ReadS [LFTagPair]
-> ReadPrec LFTagPair
-> ReadPrec [LFTagPair]
-> Read LFTagPair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LFTagPair]
$creadListPrec :: ReadPrec [LFTagPair]
readPrec :: ReadPrec LFTagPair
$creadPrec :: ReadPrec LFTagPair
readList :: ReadS [LFTagPair]
$creadList :: ReadS [LFTagPair]
readsPrec :: Int -> ReadS LFTagPair
$creadsPrec :: Int -> ReadS LFTagPair
Prelude.Read, Int -> LFTagPair -> ShowS
[LFTagPair] -> ShowS
LFTagPair -> String
(Int -> LFTagPair -> ShowS)
-> (LFTagPair -> String)
-> ([LFTagPair] -> ShowS)
-> Show LFTagPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LFTagPair] -> ShowS
$cshowList :: [LFTagPair] -> ShowS
show :: LFTagPair -> String
$cshow :: LFTagPair -> String
showsPrec :: Int -> LFTagPair -> ShowS
$cshowsPrec :: Int -> LFTagPair -> ShowS
Prelude.Show, (forall x. LFTagPair -> Rep LFTagPair x)
-> (forall x. Rep LFTagPair x -> LFTagPair) -> Generic LFTagPair
forall x. Rep LFTagPair x -> LFTagPair
forall x. LFTagPair -> Rep LFTagPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LFTagPair x -> LFTagPair
$cfrom :: forall x. LFTagPair -> Rep LFTagPair x
Prelude.Generic)

-- |
-- Create a value of 'LFTagPair' 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:
--
-- 'catalogId', 'lFTagPair_catalogId' - The identifier for the Data Catalog. By default, the account ID. The
-- Data Catalog is the persistent metadata store. It contains database
-- definitions, table definitions, and other control information to manage
-- your AWS Lake Formation environment.
--
-- 'tagKey', 'lFTagPair_tagKey' - The key-name for the tag.
--
-- 'tagValues', 'lFTagPair_tagValues' - A list of possible values an attribute can take.
newLFTagPair ::
  -- | 'tagKey'
  Prelude.Text ->
  -- | 'tagValues'
  Prelude.NonEmpty Prelude.Text ->
  LFTagPair
newLFTagPair :: Text -> NonEmpty Text -> LFTagPair
newLFTagPair Text
pTagKey_ NonEmpty Text
pTagValues_ =
  LFTagPair' :: Maybe Text -> Text -> NonEmpty Text -> LFTagPair
LFTagPair'
    { $sel:catalogId:LFTagPair' :: Maybe Text
catalogId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tagKey:LFTagPair' :: Text
tagKey = Text
pTagKey_,
      $sel:tagValues:LFTagPair' :: 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 identifier for the Data Catalog. By default, the account ID. The
-- Data Catalog is the persistent metadata store. It contains database
-- definitions, table definitions, and other control information to manage
-- your AWS Lake Formation environment.
lFTagPair_catalogId :: Lens.Lens' LFTagPair (Prelude.Maybe Prelude.Text)
lFTagPair_catalogId :: (Maybe Text -> f (Maybe Text)) -> LFTagPair -> f LFTagPair
lFTagPair_catalogId = (LFTagPair -> Maybe Text)
-> (LFTagPair -> Maybe Text -> LFTagPair)
-> Lens LFTagPair LFTagPair (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LFTagPair' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:LFTagPair' :: LFTagPair -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: LFTagPair
s@LFTagPair' {} Maybe Text
a -> LFTagPair
s {$sel:catalogId:LFTagPair' :: Maybe Text
catalogId = Maybe Text
a} :: LFTagPair)

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

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

instance Prelude.NFData LFTagPair

instance Core.ToJSON LFTagPair where
  toJSON :: LFTagPair -> Value
toJSON LFTagPair' {Maybe Text
NonEmpty Text
Text
tagValues :: NonEmpty Text
tagKey :: Text
catalogId :: Maybe Text
$sel:tagValues:LFTagPair' :: LFTagPair -> NonEmpty Text
$sel:tagKey:LFTagPair' :: LFTagPair -> Text
$sel:catalogId:LFTagPair' :: LFTagPair -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CatalogId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
catalogId,
            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)
          ]
      )