{-# 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.WorkSpaces.Types.Tag
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.WorkSpaces.Types.Tag where

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

-- | Describes a tag.
--
-- /See:/ 'newTag' smart constructor.
data Tag = Tag'
  { -- | The value of the tag.
    Tag -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The key of the tag.
    Tag -> Text
key :: Prelude.Text
  }
  deriving (Tag -> Tag -> Bool
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]
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
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. 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 value of the tag.
--
-- 'key', 'tag_key' - The key of the tag.
newTag ::
  -- | 'key'
  Prelude.Text ->
  Tag
newTag :: Text -> Tag
newTag Text
pKey_ =
  Tag' {$sel:value:Tag' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing, $sel:key:Tag' :: Text
key = Text
pKey_}

-- | The value of the tag.
tag_value :: Lens.Lens' Tag (Prelude.Maybe Prelude.Text)
tag_value :: Lens' Tag (Maybe Text)
tag_value = 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 of the tag.
tag_key :: Lens.Lens' Tag Prelude.Text
tag_key :: Lens' Tag Text
tag_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Tag' {Text
key :: Text
$sel:key:Tag' :: Tag -> Text
key} -> Text
key) (\s :: Tag
s@Tag' {} Text
a -> Tag
s {$sel:key:Tag' :: Text
key = Text
a} :: Tag)

instance Data.FromJSON Tag where
  parseJSON :: Value -> Parser Tag
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Tag"
      ( \Object
x ->
          Maybe Text -> Text -> Tag
Tag'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Value")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Key")
      )

instance Prelude.Hashable Tag where
  hashWithSalt :: Int -> Tag -> Int
hashWithSalt Int
_salt Tag' {Maybe Text
Text
key :: Text
value :: Maybe Text
$sel:key:Tag' :: Tag -> Text
$sel:value:Tag' :: Tag -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key

instance Prelude.NFData Tag where
  rnf :: Tag -> ()
rnf Tag' {Maybe Text
Text
key :: Text
value :: Maybe Text
$sel:key:Tag' :: Tag -> Text
$sel:value:Tag' :: Tag -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
key

instance Data.ToJSON Tag where
  toJSON :: Tag -> Value
toJSON Tag' {Maybe Text
Text
key :: Text
value :: Maybe Text
$sel:key:Tag' :: Tag -> Text
$sel:value:Tag' :: Tag -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value,
            forall a. a -> Maybe a
Prelude.Just (Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key)
          ]
      )