{-# 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.Forecast.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.Forecast.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

-- | The optional metadata that you apply to a resource to help you
-- categorize and organize them. Each tag consists of a key and an optional
-- value, both of which you define.
--
-- The following basic restrictions apply to tags:
--
-- -   Maximum number of tags per resource - 50.
--
-- -   For each resource, each tag key must be unique, and each tag key can
--     have only one value.
--
-- -   Maximum key length - 128 Unicode characters in UTF-8.
--
-- -   Maximum value length - 256 Unicode characters in UTF-8.
--
-- -   If your tagging schema is used across multiple services and
--     resources, remember that other services may have restrictions on
--     allowed characters. Generally allowed characters are: letters,
--     numbers, and spaces representable in UTF-8, and the following
--     characters: + - = . _ : \/ \@.
--
-- -   Tag keys and values are case sensitive.
--
-- -   Do not use @aws:@, @AWS:@, or any upper or lowercase combination of
--     such as a prefix for keys as it is reserved for AWS use. You cannot
--     edit or delete tag keys with this prefix. Values can have this
--     prefix. If a tag value has @aws@ as its prefix but the key does not,
--     then Forecast considers it to be a user tag and will count against
--     the limit of 50 tags. Tags with only the key prefix of @aws@ do not
--     count against your tags per resource limit.
--
-- /See:/ 'newTag' smart constructor.
data Tag = Tag'
  { -- | One part of a key-value pair that makes up a tag. A @key@ is a general
    -- label that acts like a category for more specific tag values.
    Tag -> Sensitive Text
key :: Data.Sensitive Prelude.Text,
    -- | The optional part of a key-value pair that makes up a tag. A @value@
    -- acts as a descriptor within a tag category (key).
    Tag -> Sensitive Text
value :: Data.Sensitive 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, 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:
--
-- 'key', 'tag_key' - One part of a key-value pair that makes up a tag. A @key@ is a general
-- label that acts like a category for more specific tag values.
--
-- 'value', 'tag_value' - The optional part of a key-value pair that makes up a tag. A @value@
-- acts as a descriptor within a tag category (key).
newTag ::
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  Tag
newTag :: Text -> Text -> Tag
newTag Text
pKey_ Text
pValue_ =
  Tag'
    { $sel:key:Tag' :: Sensitive Text
key = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pKey_,
      $sel:value:Tag' :: Sensitive Text
value = forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pValue_
    }

-- | One part of a key-value pair that makes up a tag. A @key@ is a general
-- label that acts like a category for more specific tag values.
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' {Sensitive Text
key :: Sensitive Text
$sel:key:Tag' :: Tag -> Sensitive Text
key} -> Sensitive Text
key) (\s :: Tag
s@Tag' {} Sensitive Text
a -> Tag
s {$sel:key:Tag' :: Sensitive Text
key = Sensitive Text
a} :: Tag) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

-- | The optional part of a key-value pair that makes up a tag. A @value@
-- acts as a descriptor within a tag category (key).
tag_value :: Lens.Lens' Tag Prelude.Text
tag_value :: Lens' Tag Text
tag_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Tag' {Sensitive Text
value :: Sensitive Text
$sel:value:Tag' :: Tag -> Sensitive Text
value} -> Sensitive Text
value) (\s :: Tag
s@Tag' {} Sensitive Text
a -> Tag
s {$sel:value:Tag' :: Sensitive Text
value = Sensitive Text
a} :: Tag) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

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 ->
          Sensitive Text -> Sensitive 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 a
Data..: Key
"Key")
            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
"Value")
      )

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

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

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