{-# 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.ApiGatewayV2.GetApis
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets a collection of Api resources.
--
-- This operation returns paginated results.
module Amazonka.ApiGatewayV2.GetApis
  ( -- * Creating a Request
    GetApis (..),
    newGetApis,

    -- * Request Lenses
    getApis_maxResults,
    getApis_nextToken,

    -- * Destructuring the Response
    GetApisResponse (..),
    newGetApisResponse,

    -- * Response Lenses
    getApisResponse_items,
    getApisResponse_nextToken,
    getApisResponse_httpStatus,
  )
where

import Amazonka.ApiGatewayV2.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:/ 'newGetApis' smart constructor.
data GetApis = GetApis'
  { -- | The maximum number of elements to be returned for this resource.
    GetApis -> Maybe Text
maxResults :: Prelude.Maybe Prelude.Text,
    -- | The next page of elements from this collection. Not valid for the last
    -- element of the collection.
    GetApis -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (GetApis -> GetApis -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetApis -> GetApis -> Bool
$c/= :: GetApis -> GetApis -> Bool
== :: GetApis -> GetApis -> Bool
$c== :: GetApis -> GetApis -> Bool
Prelude.Eq, ReadPrec [GetApis]
ReadPrec GetApis
Int -> ReadS GetApis
ReadS [GetApis]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetApis]
$creadListPrec :: ReadPrec [GetApis]
readPrec :: ReadPrec GetApis
$creadPrec :: ReadPrec GetApis
readList :: ReadS [GetApis]
$creadList :: ReadS [GetApis]
readsPrec :: Int -> ReadS GetApis
$creadsPrec :: Int -> ReadS GetApis
Prelude.Read, Int -> GetApis -> ShowS
[GetApis] -> ShowS
GetApis -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetApis] -> ShowS
$cshowList :: [GetApis] -> ShowS
show :: GetApis -> String
$cshow :: GetApis -> String
showsPrec :: Int -> GetApis -> ShowS
$cshowsPrec :: Int -> GetApis -> ShowS
Prelude.Show, forall x. Rep GetApis x -> GetApis
forall x. GetApis -> Rep GetApis x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetApis x -> GetApis
$cfrom :: forall x. GetApis -> Rep GetApis x
Prelude.Generic)

-- |
-- Create a value of 'GetApis' 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', 'getApis_maxResults' - The maximum number of elements to be returned for this resource.
--
-- 'nextToken', 'getApis_nextToken' - The next page of elements from this collection. Not valid for the last
-- element of the collection.
newGetApis ::
  GetApis
newGetApis :: GetApis
newGetApis =
  GetApis'
    { $sel:maxResults:GetApis' :: Maybe Text
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:GetApis' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of elements to be returned for this resource.
getApis_maxResults :: Lens.Lens' GetApis (Prelude.Maybe Prelude.Text)
getApis_maxResults :: Lens' GetApis (Maybe Text)
getApis_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApis' {Maybe Text
maxResults :: Maybe Text
$sel:maxResults:GetApis' :: GetApis -> Maybe Text
maxResults} -> Maybe Text
maxResults) (\s :: GetApis
s@GetApis' {} Maybe Text
a -> GetApis
s {$sel:maxResults:GetApis' :: Maybe Text
maxResults = Maybe Text
a} :: GetApis)

-- | The next page of elements from this collection. Not valid for the last
-- element of the collection.
getApis_nextToken :: Lens.Lens' GetApis (Prelude.Maybe Prelude.Text)
getApis_nextToken :: Lens' GetApis (Maybe Text)
getApis_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApis' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetApis' :: GetApis -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetApis
s@GetApis' {} Maybe Text
a -> GetApis
s {$sel:nextToken:GetApis' :: Maybe Text
nextToken = Maybe Text
a} :: GetApis)

instance Core.AWSPager GetApis where
  page :: GetApis -> AWSResponse GetApis -> Maybe GetApis
page GetApis
rq AWSResponse GetApis
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetApis
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetApisResponse (Maybe Text)
getApisResponse_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 GetApis
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetApisResponse (Maybe [Api])
getApisResponse_items
            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.$ GetApis
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' GetApis (Maybe Text)
getApis_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse GetApis
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetApisResponse (Maybe Text)
getApisResponse_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 GetApis where
  type AWSResponse GetApis = GetApisResponse
  request :: (Service -> Service) -> GetApis -> Request GetApis
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetApis
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetApis)))
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 [Api] -> Maybe Text -> Int -> GetApisResponse
GetApisResponse'
            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
"items" 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 GetApis where
  hashWithSalt :: Int -> GetApis -> Int
hashWithSalt Int
_salt GetApis' {Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:nextToken:GetApis' :: GetApis -> Maybe Text
$sel:maxResults:GetApis' :: GetApis -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

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

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

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

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

-- | /See:/ 'newGetApisResponse' smart constructor.
data GetApisResponse = GetApisResponse'
  { -- | The elements from this collection.
    GetApisResponse -> Maybe [Api]
items :: Prelude.Maybe [Api],
    -- | The next page of elements from this collection. Not valid for the last
    -- element of the collection.
    GetApisResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetApisResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetApisResponse -> GetApisResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetApisResponse -> GetApisResponse -> Bool
$c/= :: GetApisResponse -> GetApisResponse -> Bool
== :: GetApisResponse -> GetApisResponse -> Bool
$c== :: GetApisResponse -> GetApisResponse -> Bool
Prelude.Eq, ReadPrec [GetApisResponse]
ReadPrec GetApisResponse
Int -> ReadS GetApisResponse
ReadS [GetApisResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetApisResponse]
$creadListPrec :: ReadPrec [GetApisResponse]
readPrec :: ReadPrec GetApisResponse
$creadPrec :: ReadPrec GetApisResponse
readList :: ReadS [GetApisResponse]
$creadList :: ReadS [GetApisResponse]
readsPrec :: Int -> ReadS GetApisResponse
$creadsPrec :: Int -> ReadS GetApisResponse
Prelude.Read, Int -> GetApisResponse -> ShowS
[GetApisResponse] -> ShowS
GetApisResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetApisResponse] -> ShowS
$cshowList :: [GetApisResponse] -> ShowS
show :: GetApisResponse -> String
$cshow :: GetApisResponse -> String
showsPrec :: Int -> GetApisResponse -> ShowS
$cshowsPrec :: Int -> GetApisResponse -> ShowS
Prelude.Show, forall x. Rep GetApisResponse x -> GetApisResponse
forall x. GetApisResponse -> Rep GetApisResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetApisResponse x -> GetApisResponse
$cfrom :: forall x. GetApisResponse -> Rep GetApisResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetApisResponse' 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:
--
-- 'items', 'getApisResponse_items' - The elements from this collection.
--
-- 'nextToken', 'getApisResponse_nextToken' - The next page of elements from this collection. Not valid for the last
-- element of the collection.
--
-- 'httpStatus', 'getApisResponse_httpStatus' - The response's http status code.
newGetApisResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetApisResponse
newGetApisResponse :: Int -> GetApisResponse
newGetApisResponse Int
pHttpStatus_ =
  GetApisResponse'
    { $sel:items:GetApisResponse' :: Maybe [Api]
items = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:GetApisResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetApisResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The elements from this collection.
getApisResponse_items :: Lens.Lens' GetApisResponse (Prelude.Maybe [Api])
getApisResponse_items :: Lens' GetApisResponse (Maybe [Api])
getApisResponse_items = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApisResponse' {Maybe [Api]
items :: Maybe [Api]
$sel:items:GetApisResponse' :: GetApisResponse -> Maybe [Api]
items} -> Maybe [Api]
items) (\s :: GetApisResponse
s@GetApisResponse' {} Maybe [Api]
a -> GetApisResponse
s {$sel:items:GetApisResponse' :: Maybe [Api]
items = Maybe [Api]
a} :: GetApisResponse) 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 next page of elements from this collection. Not valid for the last
-- element of the collection.
getApisResponse_nextToken :: Lens.Lens' GetApisResponse (Prelude.Maybe Prelude.Text)
getApisResponse_nextToken :: Lens' GetApisResponse (Maybe Text)
getApisResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetApisResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetApisResponse' :: GetApisResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetApisResponse
s@GetApisResponse' {} Maybe Text
a -> GetApisResponse
s {$sel:nextToken:GetApisResponse' :: Maybe Text
nextToken = Maybe Text
a} :: GetApisResponse)

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

instance Prelude.NFData GetApisResponse where
  rnf :: GetApisResponse -> ()
rnf GetApisResponse' {Int
Maybe [Api]
Maybe Text
httpStatus :: Int
nextToken :: Maybe Text
items :: Maybe [Api]
$sel:httpStatus:GetApisResponse' :: GetApisResponse -> Int
$sel:nextToken:GetApisResponse' :: GetApisResponse -> Maybe Text
$sel:items:GetApisResponse' :: GetApisResponse -> Maybe [Api]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Api]
items
      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