{-# 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.Inspector.Types.ResourceGroupTag
-- 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.Inspector.Types.ResourceGroupTag where

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

-- | This data type is used as one of the elements of the ResourceGroup data
-- type.
--
-- /See:/ 'newResourceGroupTag' smart constructor.
data ResourceGroupTag = ResourceGroupTag'
  { -- | The value assigned to a tag key.
    ResourceGroupTag -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | A tag key.
    ResourceGroupTag -> Text
key :: Prelude.Text
  }
  deriving (ResourceGroupTag -> ResourceGroupTag -> Bool
(ResourceGroupTag -> ResourceGroupTag -> Bool)
-> (ResourceGroupTag -> ResourceGroupTag -> Bool)
-> Eq ResourceGroupTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceGroupTag -> ResourceGroupTag -> Bool
$c/= :: ResourceGroupTag -> ResourceGroupTag -> Bool
== :: ResourceGroupTag -> ResourceGroupTag -> Bool
$c== :: ResourceGroupTag -> ResourceGroupTag -> Bool
Prelude.Eq, ReadPrec [ResourceGroupTag]
ReadPrec ResourceGroupTag
Int -> ReadS ResourceGroupTag
ReadS [ResourceGroupTag]
(Int -> ReadS ResourceGroupTag)
-> ReadS [ResourceGroupTag]
-> ReadPrec ResourceGroupTag
-> ReadPrec [ResourceGroupTag]
-> Read ResourceGroupTag
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceGroupTag]
$creadListPrec :: ReadPrec [ResourceGroupTag]
readPrec :: ReadPrec ResourceGroupTag
$creadPrec :: ReadPrec ResourceGroupTag
readList :: ReadS [ResourceGroupTag]
$creadList :: ReadS [ResourceGroupTag]
readsPrec :: Int -> ReadS ResourceGroupTag
$creadsPrec :: Int -> ReadS ResourceGroupTag
Prelude.Read, Int -> ResourceGroupTag -> ShowS
[ResourceGroupTag] -> ShowS
ResourceGroupTag -> String
(Int -> ResourceGroupTag -> ShowS)
-> (ResourceGroupTag -> String)
-> ([ResourceGroupTag] -> ShowS)
-> Show ResourceGroupTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceGroupTag] -> ShowS
$cshowList :: [ResourceGroupTag] -> ShowS
show :: ResourceGroupTag -> String
$cshow :: ResourceGroupTag -> String
showsPrec :: Int -> ResourceGroupTag -> ShowS
$cshowsPrec :: Int -> ResourceGroupTag -> ShowS
Prelude.Show, (forall x. ResourceGroupTag -> Rep ResourceGroupTag x)
-> (forall x. Rep ResourceGroupTag x -> ResourceGroupTag)
-> Generic ResourceGroupTag
forall x. Rep ResourceGroupTag x -> ResourceGroupTag
forall x. ResourceGroupTag -> Rep ResourceGroupTag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceGroupTag x -> ResourceGroupTag
$cfrom :: forall x. ResourceGroupTag -> Rep ResourceGroupTag x
Prelude.Generic)

-- |
-- Create a value of 'ResourceGroupTag' 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', 'resourceGroupTag_value' - The value assigned to a tag key.
--
-- 'key', 'resourceGroupTag_key' - A tag key.
newResourceGroupTag ::
  -- | 'key'
  Prelude.Text ->
  ResourceGroupTag
newResourceGroupTag :: Text -> ResourceGroupTag
newResourceGroupTag Text
pKey_ =
  ResourceGroupTag' :: Maybe Text -> Text -> ResourceGroupTag
ResourceGroupTag'
    { $sel:value:ResourceGroupTag' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:key:ResourceGroupTag' :: Text
key = Text
pKey_
    }

-- | The value assigned to a tag key.
resourceGroupTag_value :: Lens.Lens' ResourceGroupTag (Prelude.Maybe Prelude.Text)
resourceGroupTag_value :: (Maybe Text -> f (Maybe Text))
-> ResourceGroupTag -> f ResourceGroupTag
resourceGroupTag_value = (ResourceGroupTag -> Maybe Text)
-> (ResourceGroupTag -> Maybe Text -> ResourceGroupTag)
-> Lens ResourceGroupTag ResourceGroupTag (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceGroupTag' {Maybe Text
value :: Maybe Text
$sel:value:ResourceGroupTag' :: ResourceGroupTag -> Maybe Text
value} -> Maybe Text
value) (\s :: ResourceGroupTag
s@ResourceGroupTag' {} Maybe Text
a -> ResourceGroupTag
s {$sel:value:ResourceGroupTag' :: Maybe Text
value = Maybe Text
a} :: ResourceGroupTag)

-- | A tag key.
resourceGroupTag_key :: Lens.Lens' ResourceGroupTag Prelude.Text
resourceGroupTag_key :: (Text -> f Text) -> ResourceGroupTag -> f ResourceGroupTag
resourceGroupTag_key = (ResourceGroupTag -> Text)
-> (ResourceGroupTag -> Text -> ResourceGroupTag)
-> Lens ResourceGroupTag ResourceGroupTag Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceGroupTag' {Text
key :: Text
$sel:key:ResourceGroupTag' :: ResourceGroupTag -> Text
key} -> Text
key) (\s :: ResourceGroupTag
s@ResourceGroupTag' {} Text
a -> ResourceGroupTag
s {$sel:key:ResourceGroupTag' :: Text
key = Text
a} :: ResourceGroupTag)

instance Core.FromJSON ResourceGroupTag where
  parseJSON :: Value -> Parser ResourceGroupTag
parseJSON =
    String
-> (Object -> Parser ResourceGroupTag)
-> Value
-> Parser ResourceGroupTag
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourceGroupTag"
      ( \Object
x ->
          Maybe Text -> Text -> ResourceGroupTag
ResourceGroupTag'
            (Maybe Text -> Text -> ResourceGroupTag)
-> Parser (Maybe Text) -> Parser (Text -> ResourceGroupTag)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"value") Parser (Text -> ResourceGroupTag)
-> Parser Text -> Parser ResourceGroupTag
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
"key")
      )

instance Prelude.Hashable ResourceGroupTag

instance Prelude.NFData ResourceGroupTag

instance Core.ToJSON ResourceGroupTag where
  toJSON :: ResourceGroupTag -> Value
toJSON ResourceGroupTag' {Maybe Text
Text
key :: Text
value :: Maybe Text
$sel:key:ResourceGroupTag' :: ResourceGroupTag -> Text
$sel:value:ResourceGroupTag' :: ResourceGroupTag -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value,
            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)
          ]
      )