{-# 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.CloudDirectory.ListFacetNames
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves the names of facets that exist in a schema.
--
-- This operation returns paginated results.
module Amazonka.CloudDirectory.ListFacetNames
  ( -- * Creating a Request
    ListFacetNames (..),
    newListFacetNames,

    -- * Request Lenses
    listFacetNames_maxResults,
    listFacetNames_nextToken,
    listFacetNames_schemaArn,

    -- * Destructuring the Response
    ListFacetNamesResponse (..),
    newListFacetNamesResponse,

    -- * Response Lenses
    listFacetNamesResponse_facetNames,
    listFacetNamesResponse_nextToken,
    listFacetNamesResponse_httpStatus,
  )
where

import Amazonka.CloudDirectory.Types
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 qualified Amazonka.Response as Response

-- | /See:/ 'newListFacetNames' smart constructor.
data ListFacetNames = ListFacetNames'
  { -- | The maximum number of results to retrieve.
    ListFacetNames -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | The pagination token.
    ListFacetNames -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) to retrieve facet names from.
    ListFacetNames -> Text
schemaArn :: Prelude.Text
  }
  deriving (ListFacetNames -> ListFacetNames -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListFacetNames -> ListFacetNames -> Bool
$c/= :: ListFacetNames -> ListFacetNames -> Bool
== :: ListFacetNames -> ListFacetNames -> Bool
$c== :: ListFacetNames -> ListFacetNames -> Bool
Prelude.Eq, ReadPrec [ListFacetNames]
ReadPrec ListFacetNames
Int -> ReadS ListFacetNames
ReadS [ListFacetNames]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListFacetNames]
$creadListPrec :: ReadPrec [ListFacetNames]
readPrec :: ReadPrec ListFacetNames
$creadPrec :: ReadPrec ListFacetNames
readList :: ReadS [ListFacetNames]
$creadList :: ReadS [ListFacetNames]
readsPrec :: Int -> ReadS ListFacetNames
$creadsPrec :: Int -> ReadS ListFacetNames
Prelude.Read, Int -> ListFacetNames -> ShowS
[ListFacetNames] -> ShowS
ListFacetNames -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListFacetNames] -> ShowS
$cshowList :: [ListFacetNames] -> ShowS
show :: ListFacetNames -> String
$cshow :: ListFacetNames -> String
showsPrec :: Int -> ListFacetNames -> ShowS
$cshowsPrec :: Int -> ListFacetNames -> ShowS
Prelude.Show, forall x. Rep ListFacetNames x -> ListFacetNames
forall x. ListFacetNames -> Rep ListFacetNames x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListFacetNames x -> ListFacetNames
$cfrom :: forall x. ListFacetNames -> Rep ListFacetNames x
Prelude.Generic)

-- |
-- Create a value of 'ListFacetNames' 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:
--
-- 'maxResults', 'listFacetNames_maxResults' - The maximum number of results to retrieve.
--
-- 'nextToken', 'listFacetNames_nextToken' - The pagination token.
--
-- 'schemaArn', 'listFacetNames_schemaArn' - The Amazon Resource Name (ARN) to retrieve facet names from.
newListFacetNames ::
  -- | 'schemaArn'
  Prelude.Text ->
  ListFacetNames
newListFacetNames :: Text -> ListFacetNames
newListFacetNames Text
pSchemaArn_ =
  ListFacetNames'
    { $sel:maxResults:ListFacetNames' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListFacetNames' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:schemaArn:ListFacetNames' :: Text
schemaArn = Text
pSchemaArn_
    }

-- | The maximum number of results to retrieve.
listFacetNames_maxResults :: Lens.Lens' ListFacetNames (Prelude.Maybe Prelude.Natural)
listFacetNames_maxResults :: Lens' ListFacetNames (Maybe Natural)
listFacetNames_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFacetNames' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListFacetNames' :: ListFacetNames -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListFacetNames
s@ListFacetNames' {} Maybe Natural
a -> ListFacetNames
s {$sel:maxResults:ListFacetNames' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListFacetNames)

-- | The pagination token.
listFacetNames_nextToken :: Lens.Lens' ListFacetNames (Prelude.Maybe Prelude.Text)
listFacetNames_nextToken :: Lens' ListFacetNames (Maybe Text)
listFacetNames_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFacetNames' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListFacetNames' :: ListFacetNames -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListFacetNames
s@ListFacetNames' {} Maybe Text
a -> ListFacetNames
s {$sel:nextToken:ListFacetNames' :: Maybe Text
nextToken = Maybe Text
a} :: ListFacetNames)

-- | The Amazon Resource Name (ARN) to retrieve facet names from.
listFacetNames_schemaArn :: Lens.Lens' ListFacetNames Prelude.Text
listFacetNames_schemaArn :: Lens' ListFacetNames Text
listFacetNames_schemaArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFacetNames' {Text
schemaArn :: Text
$sel:schemaArn:ListFacetNames' :: ListFacetNames -> Text
schemaArn} -> Text
schemaArn) (\s :: ListFacetNames
s@ListFacetNames' {} Text
a -> ListFacetNames
s {$sel:schemaArn:ListFacetNames' :: Text
schemaArn = Text
a} :: ListFacetNames)

instance Core.AWSPager ListFacetNames where
  page :: ListFacetNames
-> AWSResponse ListFacetNames -> Maybe ListFacetNames
page ListFacetNames
rq AWSResponse ListFacetNames
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListFacetNames
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFacetNamesResponse (Maybe Text)
listFacetNamesResponse_nextToken
            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 ListFacetNames
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFacetNamesResponse (Maybe [Text])
listFacetNamesResponse_facetNames
            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.$ ListFacetNames
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListFacetNames (Maybe Text)
listFacetNames_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListFacetNames
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListFacetNamesResponse (Maybe Text)
listFacetNamesResponse_nextToken
          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 ListFacetNames where
  type
    AWSResponse ListFacetNames =
      ListFacetNamesResponse
  request :: (Service -> Service) -> ListFacetNames -> Request ListFacetNames
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 ListFacetNames
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListFacetNames)))
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 -> ListFacetNamesResponse
ListFacetNamesResponse'
            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
"FacetNames" 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.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"NextToken")
            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 ListFacetNames where
  hashWithSalt :: Int -> ListFacetNames -> Int
hashWithSalt Int
_salt ListFacetNames' {Maybe Natural
Maybe Text
Text
schemaArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:schemaArn:ListFacetNames' :: ListFacetNames -> Text
$sel:nextToken:ListFacetNames' :: ListFacetNames -> Maybe Text
$sel:maxResults:ListFacetNames' :: ListFacetNames -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
schemaArn

instance Prelude.NFData ListFacetNames where
  rnf :: ListFacetNames -> ()
rnf ListFacetNames' {Maybe Natural
Maybe Text
Text
schemaArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:schemaArn:ListFacetNames' :: ListFacetNames -> Text
$sel:nextToken:ListFacetNames' :: ListFacetNames -> Maybe Text
$sel:maxResults:ListFacetNames' :: ListFacetNames -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
schemaArn

instance Data.ToHeaders ListFacetNames where
  toHeaders :: ListFacetNames -> ResponseHeaders
toHeaders ListFacetNames' {Maybe Natural
Maybe Text
Text
schemaArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:schemaArn:ListFacetNames' :: ListFacetNames -> Text
$sel:nextToken:ListFacetNames' :: ListFacetNames -> Maybe Text
$sel:maxResults:ListFacetNames' :: ListFacetNames -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-data-partition" forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# Text
schemaArn]

instance Data.ToJSON ListFacetNames where
  toJSON :: ListFacetNames -> Value
toJSON ListFacetNames' {Maybe Natural
Maybe Text
Text
schemaArn :: Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:schemaArn:ListFacetNames' :: ListFacetNames -> Text
$sel:nextToken:ListFacetNames' :: ListFacetNames -> Maybe Text
$sel:maxResults:ListFacetNames' :: ListFacetNames -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxResults" 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 Natural
maxResults,
            (Key
"NextToken" 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
nextToken
          ]
      )

instance Data.ToPath ListFacetNames where
  toPath :: ListFacetNames -> ByteString
toPath =
    forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/facet/list"

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

-- | /See:/ 'newListFacetNamesResponse' smart constructor.
data ListFacetNamesResponse = ListFacetNamesResponse'
  { -- | The names of facets that exist within the schema.
    ListFacetNamesResponse -> Maybe [Text]
facetNames :: Prelude.Maybe [Prelude.Text],
    -- | The pagination token.
    ListFacetNamesResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListFacetNamesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListFacetNamesResponse -> ListFacetNamesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListFacetNamesResponse -> ListFacetNamesResponse -> Bool
$c/= :: ListFacetNamesResponse -> ListFacetNamesResponse -> Bool
== :: ListFacetNamesResponse -> ListFacetNamesResponse -> Bool
$c== :: ListFacetNamesResponse -> ListFacetNamesResponse -> Bool
Prelude.Eq, ReadPrec [ListFacetNamesResponse]
ReadPrec ListFacetNamesResponse
Int -> ReadS ListFacetNamesResponse
ReadS [ListFacetNamesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListFacetNamesResponse]
$creadListPrec :: ReadPrec [ListFacetNamesResponse]
readPrec :: ReadPrec ListFacetNamesResponse
$creadPrec :: ReadPrec ListFacetNamesResponse
readList :: ReadS [ListFacetNamesResponse]
$creadList :: ReadS [ListFacetNamesResponse]
readsPrec :: Int -> ReadS ListFacetNamesResponse
$creadsPrec :: Int -> ReadS ListFacetNamesResponse
Prelude.Read, Int -> ListFacetNamesResponse -> ShowS
[ListFacetNamesResponse] -> ShowS
ListFacetNamesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListFacetNamesResponse] -> ShowS
$cshowList :: [ListFacetNamesResponse] -> ShowS
show :: ListFacetNamesResponse -> String
$cshow :: ListFacetNamesResponse -> String
showsPrec :: Int -> ListFacetNamesResponse -> ShowS
$cshowsPrec :: Int -> ListFacetNamesResponse -> ShowS
Prelude.Show, forall x. Rep ListFacetNamesResponse x -> ListFacetNamesResponse
forall x. ListFacetNamesResponse -> Rep ListFacetNamesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListFacetNamesResponse x -> ListFacetNamesResponse
$cfrom :: forall x. ListFacetNamesResponse -> Rep ListFacetNamesResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListFacetNamesResponse' 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:
--
-- 'facetNames', 'listFacetNamesResponse_facetNames' - The names of facets that exist within the schema.
--
-- 'nextToken', 'listFacetNamesResponse_nextToken' - The pagination token.
--
-- 'httpStatus', 'listFacetNamesResponse_httpStatus' - The response's http status code.
newListFacetNamesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListFacetNamesResponse
newListFacetNamesResponse :: Int -> ListFacetNamesResponse
newListFacetNamesResponse Int
pHttpStatus_ =
  ListFacetNamesResponse'
    { $sel:facetNames:ListFacetNamesResponse' :: Maybe [Text]
facetNames =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListFacetNamesResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListFacetNamesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The names of facets that exist within the schema.
listFacetNamesResponse_facetNames :: Lens.Lens' ListFacetNamesResponse (Prelude.Maybe [Prelude.Text])
listFacetNamesResponse_facetNames :: Lens' ListFacetNamesResponse (Maybe [Text])
listFacetNamesResponse_facetNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFacetNamesResponse' {Maybe [Text]
facetNames :: Maybe [Text]
$sel:facetNames:ListFacetNamesResponse' :: ListFacetNamesResponse -> Maybe [Text]
facetNames} -> Maybe [Text]
facetNames) (\s :: ListFacetNamesResponse
s@ListFacetNamesResponse' {} Maybe [Text]
a -> ListFacetNamesResponse
s {$sel:facetNames:ListFacetNamesResponse' :: Maybe [Text]
facetNames = Maybe [Text]
a} :: ListFacetNamesResponse) 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 pagination token.
listFacetNamesResponse_nextToken :: Lens.Lens' ListFacetNamesResponse (Prelude.Maybe Prelude.Text)
listFacetNamesResponse_nextToken :: Lens' ListFacetNamesResponse (Maybe Text)
listFacetNamesResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListFacetNamesResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListFacetNamesResponse' :: ListFacetNamesResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListFacetNamesResponse
s@ListFacetNamesResponse' {} Maybe Text
a -> ListFacetNamesResponse
s {$sel:nextToken:ListFacetNamesResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListFacetNamesResponse)

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

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