{-# 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.OpenSearch.ListVersions
-- 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)
--
-- List all supported versions of OpenSearch and Elasticsearch.
module Amazonka.OpenSearch.ListVersions
  ( -- * Creating a Request
    ListVersions (..),
    newListVersions,

    -- * Request Lenses
    listVersions_nextToken,
    listVersions_maxResults,

    -- * Destructuring the Response
    ListVersionsResponse (..),
    newListVersionsResponse,

    -- * Response Lenses
    listVersionsResponse_versions,
    listVersionsResponse_nextToken,
    listVersionsResponse_httpStatus,
  )
where

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

-- | Container for the parameters to the @ ListVersions @ operation.
--
-- Use @ MaxResults @ to control the maximum number of results to retrieve
-- in a single call.
--
-- Use @ NextToken @ in response to retrieve more results. If the received
-- response does not contain a NextToken, there are no more results to
-- retrieve.
--
-- /See:/ 'newListVersions' smart constructor.
data ListVersions = ListVersions'
  { ListVersions -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Set this value to limit the number of results returned. Value must be
    -- greater than 10 or it won\'t be honored.
    ListVersions -> Maybe Int
maxResults :: Prelude.Maybe Prelude.Int
  }
  deriving (ListVersions -> ListVersions -> Bool
(ListVersions -> ListVersions -> Bool)
-> (ListVersions -> ListVersions -> Bool) -> Eq ListVersions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListVersions -> ListVersions -> Bool
$c/= :: ListVersions -> ListVersions -> Bool
== :: ListVersions -> ListVersions -> Bool
$c== :: ListVersions -> ListVersions -> Bool
Prelude.Eq, ReadPrec [ListVersions]
ReadPrec ListVersions
Int -> ReadS ListVersions
ReadS [ListVersions]
(Int -> ReadS ListVersions)
-> ReadS [ListVersions]
-> ReadPrec ListVersions
-> ReadPrec [ListVersions]
-> Read ListVersions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListVersions]
$creadListPrec :: ReadPrec [ListVersions]
readPrec :: ReadPrec ListVersions
$creadPrec :: ReadPrec ListVersions
readList :: ReadS [ListVersions]
$creadList :: ReadS [ListVersions]
readsPrec :: Int -> ReadS ListVersions
$creadsPrec :: Int -> ReadS ListVersions
Prelude.Read, Int -> ListVersions -> ShowS
[ListVersions] -> ShowS
ListVersions -> String
(Int -> ListVersions -> ShowS)
-> (ListVersions -> String)
-> ([ListVersions] -> ShowS)
-> Show ListVersions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListVersions] -> ShowS
$cshowList :: [ListVersions] -> ShowS
show :: ListVersions -> String
$cshow :: ListVersions -> String
showsPrec :: Int -> ListVersions -> ShowS
$cshowsPrec :: Int -> ListVersions -> ShowS
Prelude.Show, (forall x. ListVersions -> Rep ListVersions x)
-> (forall x. Rep ListVersions x -> ListVersions)
-> Generic ListVersions
forall x. Rep ListVersions x -> ListVersions
forall x. ListVersions -> Rep ListVersions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListVersions x -> ListVersions
$cfrom :: forall x. ListVersions -> Rep ListVersions x
Prelude.Generic)

-- |
-- Create a value of 'ListVersions' 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:
--
-- 'nextToken', 'listVersions_nextToken' - Undocumented member.
--
-- 'maxResults', 'listVersions_maxResults' - Set this value to limit the number of results returned. Value must be
-- greater than 10 or it won\'t be honored.
newListVersions ::
  ListVersions
newListVersions :: ListVersions
newListVersions =
  ListVersions' :: Maybe Text -> Maybe Int -> ListVersions
ListVersions'
    { $sel:nextToken:ListVersions' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:maxResults:ListVersions' :: Maybe Int
maxResults = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | Undocumented member.
listVersions_nextToken :: Lens.Lens' ListVersions (Prelude.Maybe Prelude.Text)
listVersions_nextToken :: (Maybe Text -> f (Maybe Text)) -> ListVersions -> f ListVersions
listVersions_nextToken = (ListVersions -> Maybe Text)
-> (ListVersions -> Maybe Text -> ListVersions)
-> Lens ListVersions ListVersions (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListVersions' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListVersions' :: ListVersions -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListVersions
s@ListVersions' {} Maybe Text
a -> ListVersions
s {$sel:nextToken:ListVersions' :: Maybe Text
nextToken = Maybe Text
a} :: ListVersions)

-- | Set this value to limit the number of results returned. Value must be
-- greater than 10 or it won\'t be honored.
listVersions_maxResults :: Lens.Lens' ListVersions (Prelude.Maybe Prelude.Int)
listVersions_maxResults :: (Maybe Int -> f (Maybe Int)) -> ListVersions -> f ListVersions
listVersions_maxResults = (ListVersions -> Maybe Int)
-> (ListVersions -> Maybe Int -> ListVersions)
-> Lens ListVersions ListVersions (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListVersions' {Maybe Int
maxResults :: Maybe Int
$sel:maxResults:ListVersions' :: ListVersions -> Maybe Int
maxResults} -> Maybe Int
maxResults) (\s :: ListVersions
s@ListVersions' {} Maybe Int
a -> ListVersions
s {$sel:maxResults:ListVersions' :: Maybe Int
maxResults = Maybe Int
a} :: ListVersions)

instance Core.AWSRequest ListVersions where
  type AWSResponse ListVersions = ListVersionsResponse
  request :: ListVersions -> Request ListVersions
request = Service -> ListVersions -> Request ListVersions
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy ListVersions
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListVersions)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ListVersions))
-> Logger
-> Service
-> Proxy ListVersions
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListVersions)))
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 Text -> Int -> ListVersionsResponse
ListVersionsResponse'
            (Maybe [Text] -> Maybe Text -> Int -> ListVersionsResponse)
-> Either String (Maybe [Text])
-> Either String (Maybe Text -> Int -> ListVersionsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Versions" Either String (Maybe (Maybe [Text]))
-> Maybe [Text] -> Either String (Maybe [Text])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Maybe Text -> Int -> ListVersionsResponse)
-> Either String (Maybe Text)
-> Either String (Int -> ListVersionsResponse)
forall (f :: * -> *) a b. Applicative f => 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
"NextToken")
            Either String (Int -> ListVersionsResponse)
-> Either String Int -> Either String ListVersionsResponse
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 ListVersions

instance Prelude.NFData ListVersions

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

instance Core.ToPath ListVersions where
  toPath :: ListVersions -> ByteString
toPath =
    ByteString -> ListVersions -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/2021-01-01/opensearch/versions"

instance Core.ToQuery ListVersions where
  toQuery :: ListVersions -> QueryString
toQuery ListVersions' {Maybe Int
Maybe Text
maxResults :: Maybe Int
nextToken :: Maybe Text
$sel:maxResults:ListVersions' :: ListVersions -> Maybe Int
$sel:nextToken:ListVersions' :: ListVersions -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"nextToken" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
nextToken,
        ByteString
"maxResults" ByteString -> Maybe Int -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Int
maxResults
      ]

-- | Container for the parameters for response received from the
-- @ ListVersions @ operation.
--
-- /See:/ 'newListVersionsResponse' smart constructor.
data ListVersionsResponse = ListVersionsResponse'
  { ListVersionsResponse -> Maybe [Text]
versions :: Prelude.Maybe [Prelude.Text],
    ListVersionsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ListVersionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListVersionsResponse -> ListVersionsResponse -> Bool
(ListVersionsResponse -> ListVersionsResponse -> Bool)
-> (ListVersionsResponse -> ListVersionsResponse -> Bool)
-> Eq ListVersionsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListVersionsResponse -> ListVersionsResponse -> Bool
$c/= :: ListVersionsResponse -> ListVersionsResponse -> Bool
== :: ListVersionsResponse -> ListVersionsResponse -> Bool
$c== :: ListVersionsResponse -> ListVersionsResponse -> Bool
Prelude.Eq, ReadPrec [ListVersionsResponse]
ReadPrec ListVersionsResponse
Int -> ReadS ListVersionsResponse
ReadS [ListVersionsResponse]
(Int -> ReadS ListVersionsResponse)
-> ReadS [ListVersionsResponse]
-> ReadPrec ListVersionsResponse
-> ReadPrec [ListVersionsResponse]
-> Read ListVersionsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListVersionsResponse]
$creadListPrec :: ReadPrec [ListVersionsResponse]
readPrec :: ReadPrec ListVersionsResponse
$creadPrec :: ReadPrec ListVersionsResponse
readList :: ReadS [ListVersionsResponse]
$creadList :: ReadS [ListVersionsResponse]
readsPrec :: Int -> ReadS ListVersionsResponse
$creadsPrec :: Int -> ReadS ListVersionsResponse
Prelude.Read, Int -> ListVersionsResponse -> ShowS
[ListVersionsResponse] -> ShowS
ListVersionsResponse -> String
(Int -> ListVersionsResponse -> ShowS)
-> (ListVersionsResponse -> String)
-> ([ListVersionsResponse] -> ShowS)
-> Show ListVersionsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListVersionsResponse] -> ShowS
$cshowList :: [ListVersionsResponse] -> ShowS
show :: ListVersionsResponse -> String
$cshow :: ListVersionsResponse -> String
showsPrec :: Int -> ListVersionsResponse -> ShowS
$cshowsPrec :: Int -> ListVersionsResponse -> ShowS
Prelude.Show, (forall x. ListVersionsResponse -> Rep ListVersionsResponse x)
-> (forall x. Rep ListVersionsResponse x -> ListVersionsResponse)
-> Generic ListVersionsResponse
forall x. Rep ListVersionsResponse x -> ListVersionsResponse
forall x. ListVersionsResponse -> Rep ListVersionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListVersionsResponse x -> ListVersionsResponse
$cfrom :: forall x. ListVersionsResponse -> Rep ListVersionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListVersionsResponse' 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:
--
-- 'versions', 'listVersionsResponse_versions' - Undocumented member.
--
-- 'nextToken', 'listVersionsResponse_nextToken' - Undocumented member.
--
-- 'httpStatus', 'listVersionsResponse_httpStatus' - The response's http status code.
newListVersionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListVersionsResponse
newListVersionsResponse :: Int -> ListVersionsResponse
newListVersionsResponse Int
pHttpStatus_ =
  ListVersionsResponse' :: Maybe [Text] -> Maybe Text -> Int -> ListVersionsResponse
ListVersionsResponse'
    { $sel:versions:ListVersionsResponse' :: Maybe [Text]
versions = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListVersionsResponse' :: Maybe Text
nextToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListVersionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
listVersionsResponse_versions :: Lens.Lens' ListVersionsResponse (Prelude.Maybe [Prelude.Text])
listVersionsResponse_versions :: (Maybe [Text] -> f (Maybe [Text]))
-> ListVersionsResponse -> f ListVersionsResponse
listVersionsResponse_versions = (ListVersionsResponse -> Maybe [Text])
-> (ListVersionsResponse -> Maybe [Text] -> ListVersionsResponse)
-> Lens
     ListVersionsResponse
     ListVersionsResponse
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListVersionsResponse' {Maybe [Text]
versions :: Maybe [Text]
$sel:versions:ListVersionsResponse' :: ListVersionsResponse -> Maybe [Text]
versions} -> Maybe [Text]
versions) (\s :: ListVersionsResponse
s@ListVersionsResponse' {} Maybe [Text]
a -> ListVersionsResponse
s {$sel:versions:ListVersionsResponse' :: Maybe [Text]
versions = Maybe [Text]
a} :: ListVersionsResponse) ((Maybe [Text] -> f (Maybe [Text]))
 -> ListVersionsResponse -> f ListVersionsResponse)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> ListVersionsResponse
-> f ListVersionsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Undocumented member.
listVersionsResponse_nextToken :: Lens.Lens' ListVersionsResponse (Prelude.Maybe Prelude.Text)
listVersionsResponse_nextToken :: (Maybe Text -> f (Maybe Text))
-> ListVersionsResponse -> f ListVersionsResponse
listVersionsResponse_nextToken = (ListVersionsResponse -> Maybe Text)
-> (ListVersionsResponse -> Maybe Text -> ListVersionsResponse)
-> Lens
     ListVersionsResponse ListVersionsResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListVersionsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListVersionsResponse' :: ListVersionsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListVersionsResponse
s@ListVersionsResponse' {} Maybe Text
a -> ListVersionsResponse
s {$sel:nextToken:ListVersionsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListVersionsResponse)

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

instance Prelude.NFData ListVersionsResponse