{-# 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.AppMesh.Types.TagRef
-- 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.AppMesh.Types.TagRef where

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

-- | Optional metadata that you apply to a resource to assist with
-- categorization and organization. Each tag consists of a key and an
-- optional value, both of which you define. Tag keys can have a maximum
-- character length of 128 characters, and tag values can have a maximum
-- length of 256 characters.
--
-- /See:/ 'newTagRef' smart constructor.
data TagRef = TagRef'
  { -- | One part of a key-value pair that make up a tag. A @key@ is a general
    -- label that acts like a category for more specific tag values.
    TagRef -> Text
key :: Prelude.Text,
    -- | The optional part of a key-value pair that make up a tag. A @value@ acts
    -- as a descriptor within a tag category (key).
    TagRef -> Text
value :: Prelude.Text
  }
  deriving (TagRef -> TagRef -> Bool
(TagRef -> TagRef -> Bool)
-> (TagRef -> TagRef -> Bool) -> Eq TagRef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagRef -> TagRef -> Bool
$c/= :: TagRef -> TagRef -> Bool
== :: TagRef -> TagRef -> Bool
$c== :: TagRef -> TagRef -> Bool
Prelude.Eq, ReadPrec [TagRef]
ReadPrec TagRef
Int -> ReadS TagRef
ReadS [TagRef]
(Int -> ReadS TagRef)
-> ReadS [TagRef]
-> ReadPrec TagRef
-> ReadPrec [TagRef]
-> Read TagRef
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagRef]
$creadListPrec :: ReadPrec [TagRef]
readPrec :: ReadPrec TagRef
$creadPrec :: ReadPrec TagRef
readList :: ReadS [TagRef]
$creadList :: ReadS [TagRef]
readsPrec :: Int -> ReadS TagRef
$creadsPrec :: Int -> ReadS TagRef
Prelude.Read, Int -> TagRef -> ShowS
[TagRef] -> ShowS
TagRef -> String
(Int -> TagRef -> ShowS)
-> (TagRef -> String) -> ([TagRef] -> ShowS) -> Show TagRef
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagRef] -> ShowS
$cshowList :: [TagRef] -> ShowS
show :: TagRef -> String
$cshow :: TagRef -> String
showsPrec :: Int -> TagRef -> ShowS
$cshowsPrec :: Int -> TagRef -> ShowS
Prelude.Show, (forall x. TagRef -> Rep TagRef x)
-> (forall x. Rep TagRef x -> TagRef) -> Generic TagRef
forall x. Rep TagRef x -> TagRef
forall x. TagRef -> Rep TagRef x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagRef x -> TagRef
$cfrom :: forall x. TagRef -> Rep TagRef x
Prelude.Generic)

-- |
-- Create a value of 'TagRef' 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:
--
-- 'key', 'tagRef_key' - One part of a key-value pair that make up a tag. A @key@ is a general
-- label that acts like a category for more specific tag values.
--
-- 'value', 'tagRef_value' - The optional part of a key-value pair that make up a tag. A @value@ acts
-- as a descriptor within a tag category (key).
newTagRef ::
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  TagRef
newTagRef :: Text -> Text -> TagRef
newTagRef Text
pKey_ Text
pValue_ =
  TagRef' :: Text -> Text -> TagRef
TagRef' {$sel:key:TagRef' :: Text
key = Text
pKey_, $sel:value:TagRef' :: Text
value = Text
pValue_}

-- | One part of a key-value pair that make up a tag. A @key@ is a general
-- label that acts like a category for more specific tag values.
tagRef_key :: Lens.Lens' TagRef Prelude.Text
tagRef_key :: (Text -> f Text) -> TagRef -> f TagRef
tagRef_key = (TagRef -> Text)
-> (TagRef -> Text -> TagRef) -> Lens TagRef TagRef Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagRef' {Text
key :: Text
$sel:key:TagRef' :: TagRef -> Text
key} -> Text
key) (\s :: TagRef
s@TagRef' {} Text
a -> TagRef
s {$sel:key:TagRef' :: Text
key = Text
a} :: TagRef)

-- | The optional part of a key-value pair that make up a tag. A @value@ acts
-- as a descriptor within a tag category (key).
tagRef_value :: Lens.Lens' TagRef Prelude.Text
tagRef_value :: (Text -> f Text) -> TagRef -> f TagRef
tagRef_value = (TagRef -> Text)
-> (TagRef -> Text -> TagRef) -> Lens TagRef TagRef Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagRef' {Text
value :: Text
$sel:value:TagRef' :: TagRef -> Text
value} -> Text
value) (\s :: TagRef
s@TagRef' {} Text
a -> TagRef
s {$sel:value:TagRef' :: Text
value = Text
a} :: TagRef)

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

instance Prelude.Hashable TagRef

instance Prelude.NFData TagRef

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