{-# 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.ElastiCache.Types.Tag
-- 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.ElastiCache.Types.Tag where

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

-- | A tag that can be added to an ElastiCache cluster or replication group.
-- Tags are composed of a Key\/Value pair. You can use tags to categorize
-- and track all your ElastiCache resources, with the exception of global
-- replication group. When you add or remove tags on replication groups,
-- those actions will be replicated to all nodes in the replication group.
-- A tag with a null Value is permitted.
--
-- /See:/ 'newTag' smart constructor.
data Tag = Tag'
  { -- | The tag\'s value. May be null.
    Tag -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The key for the tag. May not be null.
    Tag -> Maybe Text
key :: Prelude.Maybe Prelude.Text
  }
  deriving (Tag -> Tag -> Bool
(Tag -> Tag -> Bool) -> (Tag -> Tag -> Bool) -> Eq Tag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tag -> Tag -> Bool
$c/= :: Tag -> Tag -> Bool
== :: Tag -> Tag -> Bool
$c== :: Tag -> Tag -> Bool
Prelude.Eq, ReadPrec [Tag]
ReadPrec Tag
Int -> ReadS Tag
ReadS [Tag]
(Int -> ReadS Tag)
-> ReadS [Tag] -> ReadPrec Tag -> ReadPrec [Tag] -> Read Tag
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Tag]
$creadListPrec :: ReadPrec [Tag]
readPrec :: ReadPrec Tag
$creadPrec :: ReadPrec Tag
readList :: ReadS [Tag]
$creadList :: ReadS [Tag]
readsPrec :: Int -> ReadS Tag
$creadsPrec :: Int -> ReadS Tag
Prelude.Read, Int -> Tag -> ShowS
[Tag] -> ShowS
Tag -> String
(Int -> Tag -> ShowS)
-> (Tag -> String) -> ([Tag] -> ShowS) -> Show Tag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tag] -> ShowS
$cshowList :: [Tag] -> ShowS
show :: Tag -> String
$cshow :: Tag -> String
showsPrec :: Int -> Tag -> ShowS
$cshowsPrec :: Int -> Tag -> ShowS
Prelude.Show, (forall x. Tag -> Rep Tag x)
-> (forall x. Rep Tag x -> Tag) -> Generic Tag
forall x. Rep Tag x -> Tag
forall x. Tag -> Rep Tag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Tag x -> Tag
$cfrom :: forall x. Tag -> Rep Tag x
Prelude.Generic)

-- |
-- Create a value of 'Tag' 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', 'tag_value' - The tag\'s value. May be null.
--
-- 'key', 'tag_key' - The key for the tag. May not be null.
newTag ::
  Tag
newTag :: Tag
newTag =
  Tag' :: Maybe Text -> Maybe Text -> Tag
Tag'
    { $sel:value:Tag' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:key:Tag' :: Maybe Text
key = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The tag\'s value. May be null.
tag_value :: Lens.Lens' Tag (Prelude.Maybe Prelude.Text)
tag_value :: (Maybe Text -> f (Maybe Text)) -> Tag -> f Tag
tag_value = (Tag -> Maybe Text)
-> (Tag -> Maybe Text -> Tag)
-> Lens Tag Tag (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Tag' {Maybe Text
value :: Maybe Text
$sel:value:Tag' :: Tag -> Maybe Text
value} -> Maybe Text
value) (\s :: Tag
s@Tag' {} Maybe Text
a -> Tag
s {$sel:value:Tag' :: Maybe Text
value = Maybe Text
a} :: Tag)

-- | The key for the tag. May not be null.
tag_key :: Lens.Lens' Tag (Prelude.Maybe Prelude.Text)
tag_key :: (Maybe Text -> f (Maybe Text)) -> Tag -> f Tag
tag_key = (Tag -> Maybe Text)
-> (Tag -> Maybe Text -> Tag)
-> Lens Tag Tag (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Tag' {Maybe Text
key :: Maybe Text
$sel:key:Tag' :: Tag -> Maybe Text
key} -> Maybe Text
key) (\s :: Tag
s@Tag' {} Maybe Text
a -> Tag
s {$sel:key:Tag' :: Maybe Text
key = Maybe Text
a} :: Tag)

instance Core.FromXML Tag where
  parseXML :: [Node] -> Either String Tag
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Tag
Tag'
      (Maybe Text -> Maybe Text -> Tag)
-> Either String (Maybe Text) -> Either String (Maybe Text -> Tag)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Value") Either String (Maybe Text -> Tag)
-> Either String (Maybe Text) -> Either String Tag
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Key")

instance Prelude.Hashable Tag

instance Prelude.NFData Tag

instance Core.ToQuery Tag where
  toQuery :: Tag -> QueryString
toQuery Tag' {Maybe Text
key :: Maybe Text
value :: Maybe Text
$sel:key:Tag' :: Tag -> Maybe Text
$sel:value:Tag' :: Tag -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"Value" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
value, ByteString
"Key" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
key]