{-# 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.CostExplorer.Types.ResourceTag
-- 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.CostExplorer.Types.ResourceTag 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 tag structure that contains a tag key and value.
--
-- Tagging is supported only for the following Cost Explorer resource
-- types:
-- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_AnomalyMonitor.html AnomalyMonitor>
-- ,
-- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_AnomalySubscription.html AnomalySubscription>
-- ,
-- <https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_CostCategory.html CostCategory>
-- .
--
-- /See:/ 'newResourceTag' smart constructor.
data ResourceTag = ResourceTag'
  { -- | The key that\'s associated with the tag.
    ResourceTag -> Text
key :: Prelude.Text,
    -- | The value that\'s associated with the tag.
    ResourceTag -> Text
value :: Prelude.Text
  }
  deriving (ResourceTag -> ResourceTag -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceTag -> ResourceTag -> Bool
$c/= :: ResourceTag -> ResourceTag -> Bool
== :: ResourceTag -> ResourceTag -> Bool
$c== :: ResourceTag -> ResourceTag -> Bool
Prelude.Eq, ReadPrec [ResourceTag]
ReadPrec ResourceTag
Int -> ReadS ResourceTag
ReadS [ResourceTag]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceTag]
$creadListPrec :: ReadPrec [ResourceTag]
readPrec :: ReadPrec ResourceTag
$creadPrec :: ReadPrec ResourceTag
readList :: ReadS [ResourceTag]
$creadList :: ReadS [ResourceTag]
readsPrec :: Int -> ReadS ResourceTag
$creadsPrec :: Int -> ReadS ResourceTag
Prelude.Read, Int -> ResourceTag -> ShowS
[ResourceTag] -> ShowS
ResourceTag -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceTag] -> ShowS
$cshowList :: [ResourceTag] -> ShowS
show :: ResourceTag -> String
$cshow :: ResourceTag -> String
showsPrec :: Int -> ResourceTag -> ShowS
$cshowsPrec :: Int -> ResourceTag -> ShowS
Prelude.Show, forall x. Rep ResourceTag x -> ResourceTag
forall x. ResourceTag -> Rep ResourceTag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceTag x -> ResourceTag
$cfrom :: forall x. ResourceTag -> Rep ResourceTag x
Prelude.Generic)

-- |
-- Create a value of 'ResourceTag' 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', 'resourceTag_key' - The key that\'s associated with the tag.
--
-- 'value', 'resourceTag_value' - The value that\'s associated with the tag.
newResourceTag ::
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  ResourceTag
newResourceTag :: Text -> Text -> ResourceTag
newResourceTag Text
pKey_ Text
pValue_ =
  ResourceTag' {$sel:key:ResourceTag' :: Text
key = Text
pKey_, $sel:value:ResourceTag' :: Text
value = Text
pValue_}

-- | The key that\'s associated with the tag.
resourceTag_key :: Lens.Lens' ResourceTag Prelude.Text
resourceTag_key :: Lens' ResourceTag Text
resourceTag_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceTag' {Text
key :: Text
$sel:key:ResourceTag' :: ResourceTag -> Text
key} -> Text
key) (\s :: ResourceTag
s@ResourceTag' {} Text
a -> ResourceTag
s {$sel:key:ResourceTag' :: Text
key = Text
a} :: ResourceTag)

-- | The value that\'s associated with the tag.
resourceTag_value :: Lens.Lens' ResourceTag Prelude.Text
resourceTag_value :: Lens' ResourceTag Text
resourceTag_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceTag' {Text
value :: Text
$sel:value:ResourceTag' :: ResourceTag -> Text
value} -> Text
value) (\s :: ResourceTag
s@ResourceTag' {} Text
a -> ResourceTag
s {$sel:value:ResourceTag' :: Text
value = Text
a} :: ResourceTag)

instance Data.FromJSON ResourceTag where
  parseJSON :: Value -> Parser ResourceTag
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ResourceTag"
      ( \Object
x ->
          Text -> Text -> ResourceTag
ResourceTag'
            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 ResourceTag where
  hashWithSalt :: Int -> ResourceTag -> Int
hashWithSalt Int
_salt ResourceTag' {Text
value :: Text
key :: Text
$sel:value:ResourceTag' :: ResourceTag -> Text
$sel:key:ResourceTag' :: ResourceTag -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value

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

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