{-# 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.MacieV2.Types.TagValuePair
-- 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.MacieV2.Types.TagValuePair where

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

-- | Specifies a tag key or tag key and value pair to use in a tag-based
-- condition that determines whether an S3 object is included or excluded
-- from a classification job. Tag keys and values are case sensitive. Also,
-- Amazon Macie doesn\'t support use of partial values or wildcard
-- characters in tag-based conditions.
--
-- /See:/ 'newTagValuePair' smart constructor.
data TagValuePair = TagValuePair'
  { -- | The tag value, associated with the specified tag key (key), to use in
    -- the condition. To specify only a tag key for a condition, specify the
    -- tag key for the key property and set this value to an empty string.
    TagValuePair -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The value for the tag key to use in the condition.
    TagValuePair -> Maybe Text
key :: Prelude.Maybe Prelude.Text
  }
  deriving (TagValuePair -> TagValuePair -> Bool
(TagValuePair -> TagValuePair -> Bool)
-> (TagValuePair -> TagValuePair -> Bool) -> Eq TagValuePair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagValuePair -> TagValuePair -> Bool
$c/= :: TagValuePair -> TagValuePair -> Bool
== :: TagValuePair -> TagValuePair -> Bool
$c== :: TagValuePair -> TagValuePair -> Bool
Prelude.Eq, ReadPrec [TagValuePair]
ReadPrec TagValuePair
Int -> ReadS TagValuePair
ReadS [TagValuePair]
(Int -> ReadS TagValuePair)
-> ReadS [TagValuePair]
-> ReadPrec TagValuePair
-> ReadPrec [TagValuePair]
-> Read TagValuePair
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagValuePair]
$creadListPrec :: ReadPrec [TagValuePair]
readPrec :: ReadPrec TagValuePair
$creadPrec :: ReadPrec TagValuePair
readList :: ReadS [TagValuePair]
$creadList :: ReadS [TagValuePair]
readsPrec :: Int -> ReadS TagValuePair
$creadsPrec :: Int -> ReadS TagValuePair
Prelude.Read, Int -> TagValuePair -> ShowS
[TagValuePair] -> ShowS
TagValuePair -> String
(Int -> TagValuePair -> ShowS)
-> (TagValuePair -> String)
-> ([TagValuePair] -> ShowS)
-> Show TagValuePair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagValuePair] -> ShowS
$cshowList :: [TagValuePair] -> ShowS
show :: TagValuePair -> String
$cshow :: TagValuePair -> String
showsPrec :: Int -> TagValuePair -> ShowS
$cshowsPrec :: Int -> TagValuePair -> ShowS
Prelude.Show, (forall x. TagValuePair -> Rep TagValuePair x)
-> (forall x. Rep TagValuePair x -> TagValuePair)
-> Generic TagValuePair
forall x. Rep TagValuePair x -> TagValuePair
forall x. TagValuePair -> Rep TagValuePair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagValuePair x -> TagValuePair
$cfrom :: forall x. TagValuePair -> Rep TagValuePair x
Prelude.Generic)

-- |
-- Create a value of 'TagValuePair' 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:
--
-- 'value', 'tagValuePair_value' - The tag value, associated with the specified tag key (key), to use in
-- the condition. To specify only a tag key for a condition, specify the
-- tag key for the key property and set this value to an empty string.
--
-- 'key', 'tagValuePair_key' - The value for the tag key to use in the condition.
newTagValuePair ::
  TagValuePair
newTagValuePair :: TagValuePair
newTagValuePair =
  TagValuePair' :: Maybe Text -> Maybe Text -> TagValuePair
TagValuePair'
    { $sel:value:TagValuePair' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:key:TagValuePair' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The tag value, associated with the specified tag key (key), to use in
-- the condition. To specify only a tag key for a condition, specify the
-- tag key for the key property and set this value to an empty string.
tagValuePair_value :: Lens.Lens' TagValuePair (Prelude.Maybe Prelude.Text)
tagValuePair_value :: (Maybe Text -> f (Maybe Text)) -> TagValuePair -> f TagValuePair
tagValuePair_value = (TagValuePair -> Maybe Text)
-> (TagValuePair -> Maybe Text -> TagValuePair)
-> Lens TagValuePair TagValuePair (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagValuePair' {Maybe Text
value :: Maybe Text
$sel:value:TagValuePair' :: TagValuePair -> Maybe Text
value} -> Maybe Text
value) (\s :: TagValuePair
s@TagValuePair' {} Maybe Text
a -> TagValuePair
s {$sel:value:TagValuePair' :: Maybe Text
value = Maybe Text
a} :: TagValuePair)

-- | The value for the tag key to use in the condition.
tagValuePair_key :: Lens.Lens' TagValuePair (Prelude.Maybe Prelude.Text)
tagValuePair_key :: (Maybe Text -> f (Maybe Text)) -> TagValuePair -> f TagValuePair
tagValuePair_key = (TagValuePair -> Maybe Text)
-> (TagValuePair -> Maybe Text -> TagValuePair)
-> Lens TagValuePair TagValuePair (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagValuePair' {Maybe Text
key :: Maybe Text
$sel:key:TagValuePair' :: TagValuePair -> Maybe Text
key} -> Maybe Text
key) (\s :: TagValuePair
s@TagValuePair' {} Maybe Text
a -> TagValuePair
s {$sel:key:TagValuePair' :: Maybe Text
key = Maybe Text
a} :: TagValuePair)

instance Core.FromJSON TagValuePair where
  parseJSON :: Value -> Parser TagValuePair
parseJSON =
    String
-> (Object -> Parser TagValuePair) -> Value -> Parser TagValuePair
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TagValuePair"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> TagValuePair
TagValuePair'
            (Maybe Text -> Maybe Text -> TagValuePair)
-> Parser (Maybe Text) -> Parser (Maybe Text -> TagValuePair)
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
"value") Parser (Maybe Text -> TagValuePair)
-> Parser (Maybe Text) -> Parser TagValuePair
forall (f :: * -> *) a b. Applicative f => 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
"key")
      )

instance Prelude.Hashable TagValuePair

instance Prelude.NFData TagValuePair

instance Core.ToJSON TagValuePair where
  toJSON :: TagValuePair -> Value
toJSON TagValuePair' {Maybe Text
key :: Maybe Text
value :: Maybe Text
$sel:key:TagValuePair' :: TagValuePair -> Maybe Text
$sel:value:TagValuePair' :: TagValuePair -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"value" 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
value,
            (Text
"key" 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
key
          ]
      )