{-# 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.ELBV2.AddTags
-- 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 the specified tags to the specified Elastic Load Balancing
-- resource. You can tag your Application Load Balancers, Network Load
-- Balancers, Gateway Load Balancers, target groups, listeners, and rules.
--
-- Each tag consists of a key and an optional value. If a resource already
-- has a tag with the same key, @AddTags@ updates its value.
module Amazonka.ELBV2.AddTags
  ( -- * Creating a Request
    AddTags (..),
    newAddTags,

    -- * Request Lenses
    addTags_resourceArns,
    addTags_tags,

    -- * Destructuring the Response
    AddTagsResponse (..),
    newAddTagsResponse,

    -- * Response Lenses
    addTagsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newAddTags' smart constructor.
data AddTags = AddTags'
  { -- | The Amazon Resource Name (ARN) of the resource.
    AddTags -> [Text]
resourceArns :: [Prelude.Text],
    -- | The tags.
    AddTags -> NonEmpty Tag
tags :: Prelude.NonEmpty Tag
  }
  deriving (AddTags -> AddTags -> Bool
(AddTags -> AddTags -> Bool)
-> (AddTags -> AddTags -> Bool) -> Eq AddTags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddTags -> AddTags -> Bool
$c/= :: AddTags -> AddTags -> Bool
== :: AddTags -> AddTags -> Bool
$c== :: AddTags -> AddTags -> Bool
Prelude.Eq, ReadPrec [AddTags]
ReadPrec AddTags
Int -> ReadS AddTags
ReadS [AddTags]
(Int -> ReadS AddTags)
-> ReadS [AddTags]
-> ReadPrec AddTags
-> ReadPrec [AddTags]
-> Read AddTags
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddTags]
$creadListPrec :: ReadPrec [AddTags]
readPrec :: ReadPrec AddTags
$creadPrec :: ReadPrec AddTags
readList :: ReadS [AddTags]
$creadList :: ReadS [AddTags]
readsPrec :: Int -> ReadS AddTags
$creadsPrec :: Int -> ReadS AddTags
Prelude.Read, Int -> AddTags -> ShowS
[AddTags] -> ShowS
AddTags -> String
(Int -> AddTags -> ShowS)
-> (AddTags -> String) -> ([AddTags] -> ShowS) -> Show AddTags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddTags] -> ShowS
$cshowList :: [AddTags] -> ShowS
show :: AddTags -> String
$cshow :: AddTags -> String
showsPrec :: Int -> AddTags -> ShowS
$cshowsPrec :: Int -> AddTags -> ShowS
Prelude.Show, (forall x. AddTags -> Rep AddTags x)
-> (forall x. Rep AddTags x -> AddTags) -> Generic AddTags
forall x. Rep AddTags x -> AddTags
forall x. AddTags -> Rep AddTags x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddTags x -> AddTags
$cfrom :: forall x. AddTags -> Rep AddTags x
Prelude.Generic)

-- |
-- Create a value of 'AddTags' 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:
--
-- 'resourceArns', 'addTags_resourceArns' - The Amazon Resource Name (ARN) of the resource.
--
-- 'tags', 'addTags_tags' - The tags.
newAddTags ::
  -- | 'tags'
  Prelude.NonEmpty Tag ->
  AddTags
newAddTags :: NonEmpty Tag -> AddTags
newAddTags NonEmpty Tag
pTags_ =
  AddTags' :: [Text] -> NonEmpty Tag -> AddTags
AddTags'
    { $sel:resourceArns:AddTags' :: [Text]
resourceArns = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:tags:AddTags' :: 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.
addTags_resourceArns :: Lens.Lens' AddTags [Prelude.Text]
addTags_resourceArns :: ([Text] -> f [Text]) -> AddTags -> f AddTags
addTags_resourceArns = (AddTags -> [Text])
-> (AddTags -> [Text] -> AddTags)
-> Lens AddTags AddTags [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddTags' {[Text]
resourceArns :: [Text]
$sel:resourceArns:AddTags' :: AddTags -> [Text]
resourceArns} -> [Text]
resourceArns) (\s :: AddTags
s@AddTags' {} [Text]
a -> AddTags
s {$sel:resourceArns:AddTags' :: [Text]
resourceArns = [Text]
a} :: AddTags) (([Text] -> f [Text]) -> AddTags -> f AddTags)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> AddTags
-> f AddTags
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The tags.
addTags_tags :: Lens.Lens' AddTags (Prelude.NonEmpty Tag)
addTags_tags :: (NonEmpty Tag -> f (NonEmpty Tag)) -> AddTags -> f AddTags
addTags_tags = (AddTags -> NonEmpty Tag)
-> (AddTags -> NonEmpty Tag -> AddTags)
-> Lens AddTags AddTags (NonEmpty Tag) (NonEmpty Tag)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddTags' {NonEmpty Tag
tags :: NonEmpty Tag
$sel:tags:AddTags' :: AddTags -> NonEmpty Tag
tags} -> NonEmpty Tag
tags) (\s :: AddTags
s@AddTags' {} NonEmpty Tag
a -> AddTags
s {$sel:tags:AddTags' :: NonEmpty Tag
tags = NonEmpty Tag
a} :: AddTags) ((NonEmpty Tag -> f (NonEmpty Tag)) -> AddTags -> f AddTags)
-> ((NonEmpty Tag -> f (NonEmpty Tag))
    -> NonEmpty Tag -> f (NonEmpty Tag))
-> (NonEmpty Tag -> f (NonEmpty Tag))
-> AddTags
-> f AddTags
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 AddTags where
  type AWSResponse AddTags = AddTagsResponse
  request :: AddTags -> Request AddTags
request = Service -> AddTags -> Request AddTags
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy AddTags
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AddTags)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse AddTags))
-> Logger
-> Service
-> Proxy AddTags
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AddTags)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"AddTagsResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> AddTagsResponse
AddTagsResponse'
            (Int -> AddTagsResponse)
-> Either String Int -> Either String AddTagsResponse
forall (f :: * -> *) a b. Functor 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 AddTags

instance Prelude.NFData AddTags

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

instance Core.ToPath AddTags where
  toPath :: AddTags -> ByteString
toPath = ByteString -> AddTags -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery AddTags where
  toQuery :: AddTags -> QueryString
toQuery AddTags' {[Text]
NonEmpty Tag
tags :: NonEmpty Tag
resourceArns :: [Text]
$sel:tags:AddTags' :: AddTags -> NonEmpty Tag
$sel:resourceArns:AddTags' :: AddTags -> [Text]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action" ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"AddTags" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2015-12-01" :: Prelude.ByteString),
        ByteString
"ResourceArns"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" [Text]
resourceArns,
        ByteString
"Tags" ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ByteString -> NonEmpty Tag -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" NonEmpty Tag
tags
      ]

-- | /See:/ 'newAddTagsResponse' smart constructor.
data AddTagsResponse = AddTagsResponse'
  { -- | The response's http status code.
    AddTagsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AddTagsResponse -> AddTagsResponse -> Bool
(AddTagsResponse -> AddTagsResponse -> Bool)
-> (AddTagsResponse -> AddTagsResponse -> Bool)
-> Eq AddTagsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddTagsResponse -> AddTagsResponse -> Bool
$c/= :: AddTagsResponse -> AddTagsResponse -> Bool
== :: AddTagsResponse -> AddTagsResponse -> Bool
$c== :: AddTagsResponse -> AddTagsResponse -> Bool
Prelude.Eq, ReadPrec [AddTagsResponse]
ReadPrec AddTagsResponse
Int -> ReadS AddTagsResponse
ReadS [AddTagsResponse]
(Int -> ReadS AddTagsResponse)
-> ReadS [AddTagsResponse]
-> ReadPrec AddTagsResponse
-> ReadPrec [AddTagsResponse]
-> Read AddTagsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddTagsResponse]
$creadListPrec :: ReadPrec [AddTagsResponse]
readPrec :: ReadPrec AddTagsResponse
$creadPrec :: ReadPrec AddTagsResponse
readList :: ReadS [AddTagsResponse]
$creadList :: ReadS [AddTagsResponse]
readsPrec :: Int -> ReadS AddTagsResponse
$creadsPrec :: Int -> ReadS AddTagsResponse
Prelude.Read, Int -> AddTagsResponse -> ShowS
[AddTagsResponse] -> ShowS
AddTagsResponse -> String
(Int -> AddTagsResponse -> ShowS)
-> (AddTagsResponse -> String)
-> ([AddTagsResponse] -> ShowS)
-> Show AddTagsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddTagsResponse] -> ShowS
$cshowList :: [AddTagsResponse] -> ShowS
show :: AddTagsResponse -> String
$cshow :: AddTagsResponse -> String
showsPrec :: Int -> AddTagsResponse -> ShowS
$cshowsPrec :: Int -> AddTagsResponse -> ShowS
Prelude.Show, (forall x. AddTagsResponse -> Rep AddTagsResponse x)
-> (forall x. Rep AddTagsResponse x -> AddTagsResponse)
-> Generic AddTagsResponse
forall x. Rep AddTagsResponse x -> AddTagsResponse
forall x. AddTagsResponse -> Rep AddTagsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddTagsResponse x -> AddTagsResponse
$cfrom :: forall x. AddTagsResponse -> Rep AddTagsResponse x
Prelude.Generic)

-- |
-- Create a value of 'AddTagsResponse' 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:
--
-- 'httpStatus', 'addTagsResponse_httpStatus' - The response's http status code.
newAddTagsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AddTagsResponse
newAddTagsResponse :: Int -> AddTagsResponse
newAddTagsResponse Int
pHttpStatus_ =
  AddTagsResponse' :: Int -> AddTagsResponse
AddTagsResponse' {$sel:httpStatus:AddTagsResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData AddTagsResponse