{-# 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.QuickSight.TagResource
-- 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)
--
-- Assigns one or more tags (key-value pairs) to the specified Amazon
-- QuickSight resource.
--
-- Tags can help you organize and categorize your resources. You can also
-- use them to scope user permissions, by granting a user permission to
-- access or change only resources with certain tag values. You can use the
-- @TagResource@ operation with a resource that already has tags. If you
-- specify a new tag key for the resource, this tag is appended to the list
-- of tags associated with the resource. If you specify a tag key that is
-- already associated with the resource, the new tag value that you specify
-- replaces the previous value for that tag.
--
-- You can associate as many as 50 tags with a resource. Amazon QuickSight
-- supports tagging on data set, data source, dashboard, and template.
--
-- Tagging for Amazon QuickSight works in a similar way to tagging for
-- other AWS services, except for the following:
--
-- -   You can\'t use tags to track AWS costs for Amazon QuickSight. This
--     restriction is because Amazon QuickSight costs are based on users
--     and SPICE capacity, which aren\'t taggable resources.
--
-- -   Amazon QuickSight doesn\'t currently support the Tag Editor for
--     Resource Groups.
module Amazonka.QuickSight.TagResource
  ( -- * Creating a Request
    TagResource (..),
    newTagResource,

    -- * Request Lenses
    tagResource_resourceArn,
    tagResource_tags,

    -- * Destructuring the Response
    TagResourceResponse (..),
    newTagResourceResponse,

    -- * Response Lenses
    tagResourceResponse_requestId,
    tagResourceResponse_status,
  )
where

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

-- | /See:/ 'newTagResource' smart constructor.
data TagResource = TagResource'
  { -- | The Amazon Resource Name (ARN) of the resource that you want to tag.
    TagResource -> Text
resourceArn :: Prelude.Text,
    -- | Contains a map of the key-value pairs for the resource tag or tags
    -- assigned to the resource.
    TagResource -> NonEmpty Tag
tags :: Prelude.NonEmpty Tag
  }
  deriving (TagResource -> TagResource -> Bool
(TagResource -> TagResource -> Bool)
-> (TagResource -> TagResource -> Bool) -> Eq TagResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagResource -> TagResource -> Bool
$c/= :: TagResource -> TagResource -> Bool
== :: TagResource -> TagResource -> Bool
$c== :: TagResource -> TagResource -> Bool
Prelude.Eq, ReadPrec [TagResource]
ReadPrec TagResource
Int -> ReadS TagResource
ReadS [TagResource]
(Int -> ReadS TagResource)
-> ReadS [TagResource]
-> ReadPrec TagResource
-> ReadPrec [TagResource]
-> Read TagResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagResource]
$creadListPrec :: ReadPrec [TagResource]
readPrec :: ReadPrec TagResource
$creadPrec :: ReadPrec TagResource
readList :: ReadS [TagResource]
$creadList :: ReadS [TagResource]
readsPrec :: Int -> ReadS TagResource
$creadsPrec :: Int -> ReadS TagResource
Prelude.Read, Int -> TagResource -> ShowS
[TagResource] -> ShowS
TagResource -> String
(Int -> TagResource -> ShowS)
-> (TagResource -> String)
-> ([TagResource] -> ShowS)
-> Show TagResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagResource] -> ShowS
$cshowList :: [TagResource] -> ShowS
show :: TagResource -> String
$cshow :: TagResource -> String
showsPrec :: Int -> TagResource -> ShowS
$cshowsPrec :: Int -> TagResource -> ShowS
Prelude.Show, (forall x. TagResource -> Rep TagResource x)
-> (forall x. Rep TagResource x -> TagResource)
-> Generic TagResource
forall x. Rep TagResource x -> TagResource
forall x. TagResource -> Rep TagResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagResource x -> TagResource
$cfrom :: forall x. TagResource -> Rep TagResource x
Prelude.Generic)

-- |
-- Create a value of 'TagResource' 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:
--
-- 'resourceArn', 'tagResource_resourceArn' - The Amazon Resource Name (ARN) of the resource that you want to tag.
--
-- 'tags', 'tagResource_tags' - Contains a map of the key-value pairs for the resource tag or tags
-- assigned to the resource.
newTagResource ::
  -- | 'resourceArn'
  Prelude.Text ->
  -- | 'tags'
  Prelude.NonEmpty Tag ->
  TagResource
newTagResource :: Text -> NonEmpty Tag -> TagResource
newTagResource Text
pResourceArn_ NonEmpty Tag
pTags_ =
  TagResource' :: Text -> NonEmpty Tag -> TagResource
TagResource'
    { $sel:resourceArn:TagResource' :: Text
resourceArn = Text
pResourceArn_,
      $sel:tags:TagResource' :: NonEmpty Tag
tags = Tagged (NonEmpty Tag) (Identity (NonEmpty Tag))
-> Tagged (NonEmpty Tag) (Identity (NonEmpty Tag))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Tag) (Identity (NonEmpty Tag))
 -> Tagged (NonEmpty Tag) (Identity (NonEmpty Tag)))
-> NonEmpty Tag -> NonEmpty Tag
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Tag
pTags_
    }

-- | The Amazon Resource Name (ARN) of the resource that you want to tag.
tagResource_resourceArn :: Lens.Lens' TagResource Prelude.Text
tagResource_resourceArn :: (Text -> f Text) -> TagResource -> f TagResource
tagResource_resourceArn = (TagResource -> Text)
-> (TagResource -> Text -> TagResource)
-> Lens TagResource TagResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResource' {Text
resourceArn :: Text
$sel:resourceArn:TagResource' :: TagResource -> Text
resourceArn} -> Text
resourceArn) (\s :: TagResource
s@TagResource' {} Text
a -> TagResource
s {$sel:resourceArn:TagResource' :: Text
resourceArn = Text
a} :: TagResource)

-- | Contains a map of the key-value pairs for the resource tag or tags
-- assigned to the resource.
tagResource_tags :: Lens.Lens' TagResource (Prelude.NonEmpty Tag)
tagResource_tags :: (NonEmpty Tag -> f (NonEmpty Tag)) -> TagResource -> f TagResource
tagResource_tags = (TagResource -> NonEmpty Tag)
-> (TagResource -> NonEmpty Tag -> TagResource)
-> Lens TagResource TagResource (NonEmpty Tag) (NonEmpty Tag)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResource' {NonEmpty Tag
tags :: NonEmpty Tag
$sel:tags:TagResource' :: TagResource -> NonEmpty Tag
tags} -> NonEmpty Tag
tags) (\s :: TagResource
s@TagResource' {} NonEmpty Tag
a -> TagResource
s {$sel:tags:TagResource' :: NonEmpty Tag
tags = NonEmpty Tag
a} :: TagResource) ((NonEmpty Tag -> f (NonEmpty Tag))
 -> TagResource -> f TagResource)
-> ((NonEmpty Tag -> f (NonEmpty Tag))
    -> NonEmpty Tag -> f (NonEmpty Tag))
-> (NonEmpty Tag -> f (NonEmpty Tag))
-> TagResource
-> f TagResource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Tag -> f (NonEmpty Tag))
-> NonEmpty Tag -> f (NonEmpty Tag)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest TagResource where
  type AWSResponse TagResource = TagResourceResponse
  request :: TagResource -> Request TagResource
request = Service -> TagResource -> Request TagResource
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy TagResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TagResource)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse TagResource))
-> Logger
-> Service
-> Proxy TagResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TagResource)))
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 -> Int -> TagResourceResponse
TagResourceResponse'
            (Maybe Text -> Int -> TagResourceResponse)
-> Either String (Maybe Text)
-> Either String (Int -> TagResourceResponse)
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
"RequestId")
            Either String (Int -> TagResourceResponse)
-> Either String Int -> Either String TagResourceResponse
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 TagResource

instance Prelude.NFData TagResource

instance Core.ToHeaders TagResource where
  toHeaders :: TagResource -> ResponseHeaders
toHeaders =
    ResponseHeaders -> TagResource -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON TagResource where
  toJSON :: TagResource -> Value
toJSON TagResource' {NonEmpty Tag
Text
tags :: NonEmpty Tag
resourceArn :: Text
$sel:tags:TagResource' :: TagResource -> NonEmpty Tag
$sel:resourceArn:TagResource' :: TagResource -> 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 -> NonEmpty Tag -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Tag
tags)]
      )

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

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

-- | /See:/ 'newTagResourceResponse' smart constructor.
data TagResourceResponse = TagResourceResponse'
  { -- | The Amazon Web Services request ID for this operation.
    TagResourceResponse -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | The HTTP status of the request.
    TagResourceResponse -> Int
status :: Prelude.Int
  }
  deriving (TagResourceResponse -> TagResourceResponse -> Bool
(TagResourceResponse -> TagResourceResponse -> Bool)
-> (TagResourceResponse -> TagResourceResponse -> Bool)
-> Eq TagResourceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagResourceResponse -> TagResourceResponse -> Bool
$c/= :: TagResourceResponse -> TagResourceResponse -> Bool
== :: TagResourceResponse -> TagResourceResponse -> Bool
$c== :: TagResourceResponse -> TagResourceResponse -> Bool
Prelude.Eq, ReadPrec [TagResourceResponse]
ReadPrec TagResourceResponse
Int -> ReadS TagResourceResponse
ReadS [TagResourceResponse]
(Int -> ReadS TagResourceResponse)
-> ReadS [TagResourceResponse]
-> ReadPrec TagResourceResponse
-> ReadPrec [TagResourceResponse]
-> Read TagResourceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagResourceResponse]
$creadListPrec :: ReadPrec [TagResourceResponse]
readPrec :: ReadPrec TagResourceResponse
$creadPrec :: ReadPrec TagResourceResponse
readList :: ReadS [TagResourceResponse]
$creadList :: ReadS [TagResourceResponse]
readsPrec :: Int -> ReadS TagResourceResponse
$creadsPrec :: Int -> ReadS TagResourceResponse
Prelude.Read, Int -> TagResourceResponse -> ShowS
[TagResourceResponse] -> ShowS
TagResourceResponse -> String
(Int -> TagResourceResponse -> ShowS)
-> (TagResourceResponse -> String)
-> ([TagResourceResponse] -> ShowS)
-> Show TagResourceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagResourceResponse] -> ShowS
$cshowList :: [TagResourceResponse] -> ShowS
show :: TagResourceResponse -> String
$cshow :: TagResourceResponse -> String
showsPrec :: Int -> TagResourceResponse -> ShowS
$cshowsPrec :: Int -> TagResourceResponse -> ShowS
Prelude.Show, (forall x. TagResourceResponse -> Rep TagResourceResponse x)
-> (forall x. Rep TagResourceResponse x -> TagResourceResponse)
-> Generic TagResourceResponse
forall x. Rep TagResourceResponse x -> TagResourceResponse
forall x. TagResourceResponse -> Rep TagResourceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagResourceResponse x -> TagResourceResponse
$cfrom :: forall x. TagResourceResponse -> Rep TagResourceResponse x
Prelude.Generic)

-- |
-- Create a value of 'TagResourceResponse' 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:
--
-- 'requestId', 'tagResourceResponse_requestId' - The Amazon Web Services request ID for this operation.
--
-- 'status', 'tagResourceResponse_status' - The HTTP status of the request.
newTagResourceResponse ::
  -- | 'status'
  Prelude.Int ->
  TagResourceResponse
newTagResourceResponse :: Int -> TagResourceResponse
newTagResourceResponse Int
pStatus_ =
  TagResourceResponse' :: Maybe Text -> Int -> TagResourceResponse
TagResourceResponse'
    { $sel:requestId:TagResourceResponse' :: Maybe Text
requestId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:status:TagResourceResponse' :: Int
status = Int
pStatus_
    }

-- | The Amazon Web Services request ID for this operation.
tagResourceResponse_requestId :: Lens.Lens' TagResourceResponse (Prelude.Maybe Prelude.Text)
tagResourceResponse_requestId :: (Maybe Text -> f (Maybe Text))
-> TagResourceResponse -> f TagResourceResponse
tagResourceResponse_requestId = (TagResourceResponse -> Maybe Text)
-> (TagResourceResponse -> Maybe Text -> TagResourceResponse)
-> Lens
     TagResourceResponse TagResourceResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResourceResponse' {Maybe Text
requestId :: Maybe Text
$sel:requestId:TagResourceResponse' :: TagResourceResponse -> Maybe Text
requestId} -> Maybe Text
requestId) (\s :: TagResourceResponse
s@TagResourceResponse' {} Maybe Text
a -> TagResourceResponse
s {$sel:requestId:TagResourceResponse' :: Maybe Text
requestId = Maybe Text
a} :: TagResourceResponse)

-- | The HTTP status of the request.
tagResourceResponse_status :: Lens.Lens' TagResourceResponse Prelude.Int
tagResourceResponse_status :: (Int -> f Int) -> TagResourceResponse -> f TagResourceResponse
tagResourceResponse_status = (TagResourceResponse -> Int)
-> (TagResourceResponse -> Int -> TagResourceResponse)
-> Lens TagResourceResponse TagResourceResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagResourceResponse' {Int
status :: Int
$sel:status:TagResourceResponse' :: TagResourceResponse -> Int
status} -> Int
status) (\s :: TagResourceResponse
s@TagResourceResponse' {} Int
a -> TagResourceResponse
s {$sel:status:TagResourceResponse' :: Int
status = Int
a} :: TagResourceResponse)

instance Prelude.NFData TagResourceResponse