{-# 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.ResourceGroupsTagging.GetTagValues
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Returns all tag values for the specified key that are used in the
-- specified Amazon Web Services Region for the calling account.
--
-- This operation supports pagination, where the response can be sent in
-- multiple pages. You should check the @PaginationToken@ response
-- parameter to determine if there are additional results available to
-- return. Repeat the query, passing the @PaginationToken@ response
-- parameter value as an input to the next request until you recieve a
-- @null@ value. A null value for @PaginationToken@ indicates that there
-- are no more results waiting to be returned.
--
-- This operation returns paginated results.
module Amazonka.ResourceGroupsTagging.GetTagValues
  ( -- * Creating a Request
    GetTagValues (..),
    newGetTagValues,

    -- * Request Lenses
    getTagValues_paginationToken,
    getTagValues_key,

    -- * Destructuring the Response
    GetTagValuesResponse (..),
    newGetTagValuesResponse,

    -- * Response Lenses
    getTagValuesResponse_paginationToken,
    getTagValuesResponse_tagValues,
    getTagValuesResponse_httpStatus,
  )
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
import qualified Amazonka.Request as Request
import Amazonka.ResourceGroupsTagging.Types
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetTagValues' smart constructor.
data GetTagValues = GetTagValues'
  { -- | Specifies a @PaginationToken@ response value from a previous request to
    -- indicate that you want the next page of results. Leave this parameter
    -- empty in your initial request.
    GetTagValues -> Maybe Text
paginationToken :: Prelude.Maybe Prelude.Text,
    -- | Specifies the tag key for which you want to list all existing values
    -- that are currently used in the specified Amazon Web Services Region for
    -- the calling account.
    GetTagValues -> Text
key :: Prelude.Text
  }
  deriving (GetTagValues -> GetTagValues -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetTagValues -> GetTagValues -> Bool
$c/= :: GetTagValues -> GetTagValues -> Bool
== :: GetTagValues -> GetTagValues -> Bool
$c== :: GetTagValues -> GetTagValues -> Bool
Prelude.Eq, ReadPrec [GetTagValues]
ReadPrec GetTagValues
Int -> ReadS GetTagValues
ReadS [GetTagValues]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetTagValues]
$creadListPrec :: ReadPrec [GetTagValues]
readPrec :: ReadPrec GetTagValues
$creadPrec :: ReadPrec GetTagValues
readList :: ReadS [GetTagValues]
$creadList :: ReadS [GetTagValues]
readsPrec :: Int -> ReadS GetTagValues
$creadsPrec :: Int -> ReadS GetTagValues
Prelude.Read, Int -> GetTagValues -> ShowS
[GetTagValues] -> ShowS
GetTagValues -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetTagValues] -> ShowS
$cshowList :: [GetTagValues] -> ShowS
show :: GetTagValues -> String
$cshow :: GetTagValues -> String
showsPrec :: Int -> GetTagValues -> ShowS
$cshowsPrec :: Int -> GetTagValues -> ShowS
Prelude.Show, forall x. Rep GetTagValues x -> GetTagValues
forall x. GetTagValues -> Rep GetTagValues x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetTagValues x -> GetTagValues
$cfrom :: forall x. GetTagValues -> Rep GetTagValues x
Prelude.Generic)

-- |
-- Create a value of 'GetTagValues' 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:
--
-- 'paginationToken', 'getTagValues_paginationToken' - Specifies a @PaginationToken@ response value from a previous request to
-- indicate that you want the next page of results. Leave this parameter
-- empty in your initial request.
--
-- 'key', 'getTagValues_key' - Specifies the tag key for which you want to list all existing values
-- that are currently used in the specified Amazon Web Services Region for
-- the calling account.
newGetTagValues ::
  -- | 'key'
  Prelude.Text ->
  GetTagValues
newGetTagValues :: Text -> GetTagValues
newGetTagValues Text
pKey_ =
  GetTagValues'
    { $sel:paginationToken:GetTagValues' :: Maybe Text
paginationToken = forall a. Maybe a
Prelude.Nothing,
      $sel:key:GetTagValues' :: Text
key = Text
pKey_
    }

-- | Specifies a @PaginationToken@ response value from a previous request to
-- indicate that you want the next page of results. Leave this parameter
-- empty in your initial request.
getTagValues_paginationToken :: Lens.Lens' GetTagValues (Prelude.Maybe Prelude.Text)
getTagValues_paginationToken :: Lens' GetTagValues (Maybe Text)
getTagValues_paginationToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTagValues' {Maybe Text
paginationToken :: Maybe Text
$sel:paginationToken:GetTagValues' :: GetTagValues -> Maybe Text
paginationToken} -> Maybe Text
paginationToken) (\s :: GetTagValues
s@GetTagValues' {} Maybe Text
a -> GetTagValues
s {$sel:paginationToken:GetTagValues' :: Maybe Text
paginationToken = Maybe Text
a} :: GetTagValues)

-- | Specifies the tag key for which you want to list all existing values
-- that are currently used in the specified Amazon Web Services Region for
-- the calling account.
getTagValues_key :: Lens.Lens' GetTagValues Prelude.Text
getTagValues_key :: Lens' GetTagValues Text
getTagValues_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTagValues' {Text
key :: Text
$sel:key:GetTagValues' :: GetTagValues -> Text
key} -> Text
key) (\s :: GetTagValues
s@GetTagValues' {} Text
a -> GetTagValues
s {$sel:key:GetTagValues' :: Text
key = Text
a} :: GetTagValues)

instance Core.AWSPager GetTagValues where
  page :: GetTagValues -> AWSResponse GetTagValues -> Maybe GetTagValues
page GetTagValues
rq AWSResponse GetTagValues
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetTagValues
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetTagValuesResponse (Maybe Text)
getTagValuesResponse_paginationToken
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetTagValues
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetTagValuesResponse (Maybe [Text])
getTagValuesResponse_tagValues
            forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
        ) =
        forall a. Maybe a
Prelude.Nothing
    | Bool
Prelude.otherwise =
        forall a. a -> Maybe a
Prelude.Just
          forall a b. (a -> b) -> a -> b
Prelude.$ GetTagValues
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' GetTagValues (Maybe Text)
getTagValues_paginationToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse GetTagValues
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetTagValuesResponse (Maybe Text)
getTagValuesResponse_paginationToken
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just

instance Core.AWSRequest GetTagValues where
  type AWSResponse GetTagValues = GetTagValuesResponse
  request :: (Service -> Service) -> GetTagValues -> Request GetTagValues
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetTagValues
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetTagValues)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Maybe [Text] -> Int -> GetTagValuesResponse
GetTagValuesResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"PaginationToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"TagValues" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetTagValues where
  hashWithSalt :: Int -> GetTagValues -> Int
hashWithSalt Int
_salt GetTagValues' {Maybe Text
Text
key :: Text
paginationToken :: Maybe Text
$sel:key:GetTagValues' :: GetTagValues -> Text
$sel:paginationToken:GetTagValues' :: GetTagValues -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
paginationToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key

instance Prelude.NFData GetTagValues where
  rnf :: GetTagValues -> ()
rnf GetTagValues' {Maybe Text
Text
key :: Text
paginationToken :: Maybe Text
$sel:key:GetTagValues' :: GetTagValues -> Text
$sel:paginationToken:GetTagValues' :: GetTagValues -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
paginationToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
key

instance Data.ToHeaders GetTagValues where
  toHeaders :: GetTagValues -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"ResourceGroupsTaggingAPI_20170126.GetTagValues" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON GetTagValues where
  toJSON :: GetTagValues -> Value
toJSON GetTagValues' {Maybe Text
Text
key :: Text
paginationToken :: Maybe Text
$sel:key:GetTagValues' :: GetTagValues -> Text
$sel:paginationToken:GetTagValues' :: GetTagValues -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"PaginationToken" 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
paginationToken,
            forall a. a -> Maybe a
Prelude.Just (Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key)
          ]
      )

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

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

-- | /See:/ 'newGetTagValuesResponse' smart constructor.
data GetTagValuesResponse = GetTagValuesResponse'
  { -- | A string that indicates that there is more data available than this
    -- response contains. To receive the next part of the response, specify
    -- this response value as the @PaginationToken@ value in the request for
    -- the next page.
    GetTagValuesResponse -> Maybe Text
paginationToken :: Prelude.Maybe Prelude.Text,
    -- | A list of all tag values for the specified key currently used in the
    -- specified Amazon Web Services Region for the calling account.
    GetTagValuesResponse -> Maybe [Text]
tagValues :: Prelude.Maybe [Prelude.Text],
    -- | The response's http status code.
    GetTagValuesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetTagValuesResponse -> GetTagValuesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetTagValuesResponse -> GetTagValuesResponse -> Bool
$c/= :: GetTagValuesResponse -> GetTagValuesResponse -> Bool
== :: GetTagValuesResponse -> GetTagValuesResponse -> Bool
$c== :: GetTagValuesResponse -> GetTagValuesResponse -> Bool
Prelude.Eq, ReadPrec [GetTagValuesResponse]
ReadPrec GetTagValuesResponse
Int -> ReadS GetTagValuesResponse
ReadS [GetTagValuesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetTagValuesResponse]
$creadListPrec :: ReadPrec [GetTagValuesResponse]
readPrec :: ReadPrec GetTagValuesResponse
$creadPrec :: ReadPrec GetTagValuesResponse
readList :: ReadS [GetTagValuesResponse]
$creadList :: ReadS [GetTagValuesResponse]
readsPrec :: Int -> ReadS GetTagValuesResponse
$creadsPrec :: Int -> ReadS GetTagValuesResponse
Prelude.Read, Int -> GetTagValuesResponse -> ShowS
[GetTagValuesResponse] -> ShowS
GetTagValuesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetTagValuesResponse] -> ShowS
$cshowList :: [GetTagValuesResponse] -> ShowS
show :: GetTagValuesResponse -> String
$cshow :: GetTagValuesResponse -> String
showsPrec :: Int -> GetTagValuesResponse -> ShowS
$cshowsPrec :: Int -> GetTagValuesResponse -> ShowS
Prelude.Show, forall x. Rep GetTagValuesResponse x -> GetTagValuesResponse
forall x. GetTagValuesResponse -> Rep GetTagValuesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetTagValuesResponse x -> GetTagValuesResponse
$cfrom :: forall x. GetTagValuesResponse -> Rep GetTagValuesResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetTagValuesResponse' 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:
--
-- 'paginationToken', 'getTagValuesResponse_paginationToken' - A string that indicates that there is more data available than this
-- response contains. To receive the next part of the response, specify
-- this response value as the @PaginationToken@ value in the request for
-- the next page.
--
-- 'tagValues', 'getTagValuesResponse_tagValues' - A list of all tag values for the specified key currently used in the
-- specified Amazon Web Services Region for the calling account.
--
-- 'httpStatus', 'getTagValuesResponse_httpStatus' - The response's http status code.
newGetTagValuesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetTagValuesResponse
newGetTagValuesResponse :: Int -> GetTagValuesResponse
newGetTagValuesResponse Int
pHttpStatus_ =
  GetTagValuesResponse'
    { $sel:paginationToken:GetTagValuesResponse' :: Maybe Text
paginationToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:tagValues:GetTagValuesResponse' :: Maybe [Text]
tagValues = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetTagValuesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A string that indicates that there is more data available than this
-- response contains. To receive the next part of the response, specify
-- this response value as the @PaginationToken@ value in the request for
-- the next page.
getTagValuesResponse_paginationToken :: Lens.Lens' GetTagValuesResponse (Prelude.Maybe Prelude.Text)
getTagValuesResponse_paginationToken :: Lens' GetTagValuesResponse (Maybe Text)
getTagValuesResponse_paginationToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTagValuesResponse' {Maybe Text
paginationToken :: Maybe Text
$sel:paginationToken:GetTagValuesResponse' :: GetTagValuesResponse -> Maybe Text
paginationToken} -> Maybe Text
paginationToken) (\s :: GetTagValuesResponse
s@GetTagValuesResponse' {} Maybe Text
a -> GetTagValuesResponse
s {$sel:paginationToken:GetTagValuesResponse' :: Maybe Text
paginationToken = Maybe Text
a} :: GetTagValuesResponse)

-- | A list of all tag values for the specified key currently used in the
-- specified Amazon Web Services Region for the calling account.
getTagValuesResponse_tagValues :: Lens.Lens' GetTagValuesResponse (Prelude.Maybe [Prelude.Text])
getTagValuesResponse_tagValues :: Lens' GetTagValuesResponse (Maybe [Text])
getTagValuesResponse_tagValues = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetTagValuesResponse' {Maybe [Text]
tagValues :: Maybe [Text]
$sel:tagValues:GetTagValuesResponse' :: GetTagValuesResponse -> Maybe [Text]
tagValues} -> Maybe [Text]
tagValues) (\s :: GetTagValuesResponse
s@GetTagValuesResponse' {} Maybe [Text]
a -> GetTagValuesResponse
s {$sel:tagValues:GetTagValuesResponse' :: Maybe [Text]
tagValues = Maybe [Text]
a} :: GetTagValuesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetTagValuesResponse where
  rnf :: GetTagValuesResponse -> ()
rnf GetTagValuesResponse' {Int
Maybe [Text]
Maybe Text
httpStatus :: Int
tagValues :: Maybe [Text]
paginationToken :: Maybe Text
$sel:httpStatus:GetTagValuesResponse' :: GetTagValuesResponse -> Int
$sel:tagValues:GetTagValuesResponse' :: GetTagValuesResponse -> Maybe [Text]
$sel:paginationToken:GetTagValuesResponse' :: GetTagValuesResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
paginationToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
tagValues
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus