{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ResourceGroups.Tag
-- 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)
--
-- Adds tags to a resource group with the specified ARN. Existing tags on a
-- resource group are not changed if they are not specified in the request
-- parameters.
--
-- Do not store personally identifiable information (PII) or other
-- confidential or sensitive information in tags. We use tags to provide
-- you with billing and administration services. Tags are not intended to
-- be used for private or sensitive data.
--
-- __Minimum permissions__
--
-- To run this command, you must have the following permissions:
--
-- -   @resource-groups:Tag@
module Amazonka.ResourceGroups.Tag
  ( -- * Creating a Request
    Tag (..),
    newTag,

    -- * Request Lenses
    tag_arn,
    tag_tags,

    -- * Destructuring the Response
    TagResponse (..),
    newTagResponse,

    -- * Response Lenses
    tagResponse_arn,
    tagResponse_tags,
    tagResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import Amazonka.ResourceGroups.Types
import qualified Amazonka.Response as Response

-- | /See:/ 'newTag' smart constructor.
data Tag = Tag'
  { -- | The ARN of the resource group to which to add tags.
    Tag -> Text
arn :: Prelude.Text,
    -- | The tags to add to the specified resource group. A tag is a
    -- string-to-string map of key-value pairs.
    Tag -> HashMap Text Text
tags :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (Tag -> Tag -> Bool
(Tag -> Tag -> Bool) -> (Tag -> Tag -> Bool) -> Eq Tag
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]
(Int -> ReadS Tag)
-> ReadS [Tag] -> ReadPrec Tag -> ReadPrec [Tag] -> Read 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
(Int -> Tag -> ShowS)
-> (Tag -> String) -> ([Tag] -> ShowS) -> Show Tag
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. Tag -> Rep Tag x)
-> (forall x. Rep Tag x -> Tag) -> Generic Tag
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:
--
-- 'arn', 'tag_arn' - The ARN of the resource group to which to add tags.
--
-- 'tags', 'tag_tags' - The tags to add to the specified resource group. A tag is a
-- string-to-string map of key-value pairs.
newTag ::
  -- | 'arn'
  Prelude.Text ->
  Tag
newTag :: Text -> Tag
newTag Text
pArn_ =
  Tag' :: Text -> HashMap Text Text -> Tag
Tag' {$sel:arn:Tag' :: Text
arn = Text
pArn_, $sel:tags:Tag' :: HashMap Text Text
tags = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty}

-- | The ARN of the resource group to which to add tags.
tag_arn :: Lens.Lens' Tag Prelude.Text
tag_arn :: (Text -> f Text) -> Tag -> f Tag
tag_arn = (Tag -> Text) -> (Tag -> Text -> Tag) -> Lens Tag Tag Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Tag' {Text
arn :: Text
$sel:arn:Tag' :: Tag -> Text
arn} -> Text
arn) (\s :: Tag
s@Tag' {} Text
a -> Tag
s {$sel:arn:Tag' :: Text
arn = Text
a} :: Tag)

-- | The tags to add to the specified resource group. A tag is a
-- string-to-string map of key-value pairs.
tag_tags :: Lens.Lens' Tag (Prelude.HashMap Prelude.Text Prelude.Text)
tag_tags :: (HashMap Text Text -> f (HashMap Text Text)) -> Tag -> f Tag
tag_tags = (Tag -> HashMap Text Text)
-> (Tag -> HashMap Text Text -> Tag)
-> Lens Tag Tag (HashMap Text Text) (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Tag' {HashMap Text Text
tags :: HashMap Text Text
$sel:tags:Tag' :: Tag -> HashMap Text Text
tags} -> HashMap Text Text
tags) (\s :: Tag
s@Tag' {} HashMap Text Text
a -> Tag
s {$sel:tags:Tag' :: HashMap Text Text
tags = HashMap Text Text
a} :: Tag) ((HashMap Text Text -> f (HashMap Text Text)) -> Tag -> f Tag)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> Tag
-> f Tag
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest Tag where
  type AWSResponse Tag = TagResponse
  request :: Tag -> Request Tag
request = Service -> Tag -> Request Tag
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy Tag
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Tag)))
response =
    (Int
 -> ResponseHeaders -> Object -> Either String (AWSResponse Tag))
-> Logger
-> Service
-> Proxy Tag
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Tag)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Maybe (HashMap Text Text) -> Int -> TagResponse
TagResponse'
            (Maybe Text -> Maybe (HashMap Text Text) -> Int -> TagResponse)
-> Either String (Maybe Text)
-> Either String (Maybe (HashMap Text Text) -> Int -> TagResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Arn")
            Either String (Maybe (HashMap Text Text) -> Int -> TagResponse)
-> Either String (Maybe (HashMap Text Text))
-> Either String (Int -> TagResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Tags" Either String (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text)
-> Either String (Maybe (HashMap Text Text))
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> TagResponse)
-> Either String Int -> Either String TagResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable Tag

instance Prelude.NFData Tag

instance Core.ToHeaders Tag where
  toHeaders :: Tag -> ResponseHeaders
toHeaders = ResponseHeaders -> Tag -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON Tag where
  toJSON :: Tag -> Value
toJSON Tag' {Text
HashMap Text Text
tags :: HashMap Text Text
arn :: Text
$sel:tags:Tag' :: Tag -> HashMap Text Text
$sel:arn:Tag' :: Tag -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
tags)]
      )

instance Core.ToPath Tag where
  toPath :: Tag -> ByteString
toPath Tag' {Text
HashMap Text Text
tags :: HashMap Text Text
arn :: Text
$sel:tags:Tag' :: Tag -> HashMap Text Text
$sel:arn:Tag' :: Tag -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/resources/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
arn, ByteString
"/tags"]

instance Core.ToQuery Tag where
  toQuery :: Tag -> QueryString
toQuery = QueryString -> Tag -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newTagResponse' smart constructor.
data TagResponse = TagResponse'
  { -- | The ARN of the tagged resource.
    TagResponse -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The tags that have been added to the specified resource group.
    TagResponse -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The response's http status code.
    TagResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (TagResponse -> TagResponse -> Bool
(TagResponse -> TagResponse -> Bool)
-> (TagResponse -> TagResponse -> Bool) -> Eq TagResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagResponse -> TagResponse -> Bool
$c/= :: TagResponse -> TagResponse -> Bool
== :: TagResponse -> TagResponse -> Bool
$c== :: TagResponse -> TagResponse -> Bool
Prelude.Eq, ReadPrec [TagResponse]
ReadPrec TagResponse
Int -> ReadS TagResponse
ReadS [TagResponse]
(Int -> ReadS TagResponse)
-> ReadS [TagResponse]
-> ReadPrec TagResponse
-> ReadPrec [TagResponse]
-> Read TagResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagResponse]
$creadListPrec :: ReadPrec [TagResponse]
readPrec :: ReadPrec TagResponse
$creadPrec :: ReadPrec TagResponse
readList :: ReadS [TagResponse]
$creadList :: ReadS [TagResponse]
readsPrec :: Int -> ReadS TagResponse
$creadsPrec :: Int -> ReadS TagResponse
Prelude.Read, Int -> TagResponse -> ShowS
[TagResponse] -> ShowS
TagResponse -> String
(Int -> TagResponse -> ShowS)
-> (TagResponse -> String)
-> ([TagResponse] -> ShowS)
-> Show TagResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagResponse] -> ShowS
$cshowList :: [TagResponse] -> ShowS
show :: TagResponse -> String
$cshow :: TagResponse -> String
showsPrec :: Int -> TagResponse -> ShowS
$cshowsPrec :: Int -> TagResponse -> ShowS
Prelude.Show, (forall x. TagResponse -> Rep TagResponse x)
-> (forall x. Rep TagResponse x -> TagResponse)
-> Generic TagResponse
forall x. Rep TagResponse x -> TagResponse
forall x. TagResponse -> Rep TagResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagResponse x -> TagResponse
$cfrom :: forall x. TagResponse -> Rep TagResponse x
Prelude.Generic)

-- |
-- Create a value of 'TagResponse' 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:
--
-- 'arn', 'tagResponse_arn' - The ARN of the tagged resource.
--
-- 'tags', 'tagResponse_tags' - The tags that have been added to the specified resource group.
--
-- 'httpStatus', 'tagResponse_httpStatus' - The response's http status code.
newTagResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TagResponse
newTagResponse :: Int -> TagResponse
newTagResponse Int
pHttpStatus_ =
  TagResponse' :: Maybe Text -> Maybe (HashMap Text Text) -> Int -> TagResponse
TagResponse'
    { $sel:arn:TagResponse' :: Maybe Text
arn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:TagResponse' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TagResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the tagged resource.
tagResponse_arn :: Lens.Lens' TagResponse (Prelude.Maybe Prelude.Text)
tagResponse_arn :: (Maybe Text -> f (Maybe Text)) -> TagResponse -> f TagResponse
tagResponse_arn = (TagResponse -> Maybe Text)
-> (TagResponse -> Maybe Text -> TagResponse)
-> Lens TagResponse TagResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:TagResponse' :: TagResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: TagResponse
s@TagResponse' {} Maybe Text
a -> TagResponse
s {$sel:arn:TagResponse' :: Maybe Text
arn = Maybe Text
a} :: TagResponse)

-- | The tags that have been added to the specified resource group.
tagResponse_tags :: Lens.Lens' TagResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
tagResponse_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> TagResponse -> f TagResponse
tagResponse_tags = (TagResponse -> Maybe (HashMap Text Text))
-> (TagResponse -> Maybe (HashMap Text Text) -> TagResponse)
-> Lens
     TagResponse
     TagResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResponse' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:TagResponse' :: TagResponse -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: TagResponse
s@TagResponse' {} Maybe (HashMap Text Text)
a -> TagResponse
s {$sel:tags:TagResponse' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: TagResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> TagResponse -> f TagResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> TagResponse
-> f TagResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
tagResponse_httpStatus :: Lens.Lens' TagResponse Prelude.Int
tagResponse_httpStatus :: (Int -> f Int) -> TagResponse -> f TagResponse
tagResponse_httpStatus = (TagResponse -> Int)
-> (TagResponse -> Int -> TagResponse)
-> Lens TagResponse TagResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResponse' {Int
httpStatus :: Int
$sel:httpStatus:TagResponse' :: TagResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: TagResponse
s@TagResponse' {} Int
a -> TagResponse
s {$sel:httpStatus:TagResponse' :: Int
httpStatus = Int
a} :: TagResponse)

instance Prelude.NFData TagResponse