{-# 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.FMS.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.FMS.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 resource tags that Firewall Manager uses to determine if a
-- particular resource should be included or excluded from the Firewall
-- Manager policy. Tags enable you to categorize your Amazon Web Services
-- resources in different ways, for example, by purpose, owner, or
-- environment. Each tag consists of a key and an optional value. Firewall
-- Manager combines the tags with \"AND\" so that, if you add more than one
-- tag to a policy scope, a resource must have all the specified tags to be
-- included or excluded. For more information, see
-- <https://docs.aws.amazon.com/awsconsolehelpdocs/latest/gsg/tag-editor.html Working with Tag Editor>.
--
-- /See:/ 'newResourceTag' smart constructor.
data ResourceTag = ResourceTag'
  { -- | The resource tag value.
    ResourceTag -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The resource tag key.
    ResourceTag -> Text
key :: 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:
--
-- 'value', 'resourceTag_value' - The resource tag value.
--
-- 'key', 'resourceTag_key' - The resource tag key.
newResourceTag ::
  -- | 'key'
  Prelude.Text ->
  ResourceTag
newResourceTag :: Text -> ResourceTag
newResourceTag Text
pKey_ =
  ResourceTag' {$sel:value:ResourceTag' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing, $sel:key:ResourceTag' :: Text
key = Text
pKey_}

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

-- | The resource tag key.
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)

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 ->
          Maybe 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 (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 ResourceTag where
  hashWithSalt :: Int -> ResourceTag -> Int
hashWithSalt Int
_salt ResourceTag' {Maybe Text
Text
key :: Text
value :: Maybe Text
$sel:key:ResourceTag' :: ResourceTag -> Text
$sel:value:ResourceTag' :: ResourceTag -> 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 ResourceTag where
  rnf :: ResourceTag -> ()
rnf ResourceTag' {Maybe Text
Text
key :: Text
value :: Maybe Text
$sel:key:ResourceTag' :: ResourceTag -> Text
$sel:value:ResourceTag' :: ResourceTag -> 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 ResourceTag where
  toJSON :: ResourceTag -> Value
toJSON ResourceTag' {Maybe Text
Text
key :: Text
value :: Maybe Text
$sel:key:ResourceTag' :: ResourceTag -> Text
$sel:value:ResourceTag' :: ResourceTag -> 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)
          ]
      )