{-# 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.GetIntegrations
-- 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 the Integrations for an API.
--
-- This operation returns paginated results.
module Amazonka.ApiGatewayV2.GetIntegrations
  ( -- * Creating a Request
    GetIntegrations (..),
    newGetIntegrations,

    -- * Request Lenses
    getIntegrations_maxResults,
    getIntegrations_nextToken,
    getIntegrations_apiId,

    -- * Destructuring the Response
    GetIntegrationsResponse (..),
    newGetIntegrationsResponse,

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

-- |
-- Create a value of 'GetIntegrations' 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', 'getIntegrations_maxResults' - The maximum number of elements to be returned for this resource.
--
-- 'nextToken', 'getIntegrations_nextToken' - The next page of elements from this collection. Not valid for the last
-- element of the collection.
--
-- 'apiId', 'getIntegrations_apiId' - The API identifier.
newGetIntegrations ::
  -- | 'apiId'
  Prelude.Text ->
  GetIntegrations
newGetIntegrations :: Text -> GetIntegrations
newGetIntegrations Text
pApiId_ =
  GetIntegrations'
    { $sel:maxResults:GetIntegrations' :: Maybe Text
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:GetIntegrations' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:apiId:GetIntegrations' :: Text
apiId = Text
pApiId_
    }

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

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

-- | The API identifier.
getIntegrations_apiId :: Lens.Lens' GetIntegrations Prelude.Text
getIntegrations_apiId :: Lens' GetIntegrations Text
getIntegrations_apiId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetIntegrations' {Text
apiId :: Text
$sel:apiId:GetIntegrations' :: GetIntegrations -> Text
apiId} -> Text
apiId) (\s :: GetIntegrations
s@GetIntegrations' {} Text
a -> GetIntegrations
s {$sel:apiId:GetIntegrations' :: Text
apiId = Text
a} :: GetIntegrations)

instance Core.AWSPager GetIntegrations where
  page :: GetIntegrations
-> AWSResponse GetIntegrations -> Maybe GetIntegrations
page GetIntegrations
rq AWSResponse GetIntegrations
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse GetIntegrations
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetIntegrationsResponse (Maybe Text)
getIntegrationsResponse_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 GetIntegrations
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetIntegrationsResponse (Maybe [Integration])
getIntegrationsResponse_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.$ GetIntegrations
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' GetIntegrations (Maybe Text)
getIntegrations_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse GetIntegrations
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' GetIntegrationsResponse (Maybe Text)
getIntegrationsResponse_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 GetIntegrations where
  type
    AWSResponse GetIntegrations =
      GetIntegrationsResponse
  request :: (Service -> Service) -> GetIntegrations -> Request GetIntegrations
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 GetIntegrations
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetIntegrations)))
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 [Integration] -> Maybe Text -> Int -> GetIntegrationsResponse
GetIntegrationsResponse'
            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 GetIntegrations where
  hashWithSalt :: Int -> GetIntegrations -> Int
hashWithSalt Int
_salt GetIntegrations' {Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:apiId:GetIntegrations' :: GetIntegrations -> Text
$sel:nextToken:GetIntegrations' :: GetIntegrations -> Maybe Text
$sel:maxResults:GetIntegrations' :: GetIntegrations -> 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
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
apiId

instance Prelude.NFData GetIntegrations where
  rnf :: GetIntegrations -> ()
rnf GetIntegrations' {Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:apiId:GetIntegrations' :: GetIntegrations -> Text
$sel:nextToken:GetIntegrations' :: GetIntegrations -> Maybe Text
$sel:maxResults:GetIntegrations' :: GetIntegrations -> 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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
apiId

instance Data.ToHeaders GetIntegrations where
  toHeaders :: GetIntegrations -> 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 GetIntegrations where
  toPath :: GetIntegrations -> ByteString
toPath GetIntegrations' {Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:apiId:GetIntegrations' :: GetIntegrations -> Text
$sel:nextToken:GetIntegrations' :: GetIntegrations -> Maybe Text
$sel:maxResults:GetIntegrations' :: GetIntegrations -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/v2/apis/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
apiId, ByteString
"/integrations"]

instance Data.ToQuery GetIntegrations where
  toQuery :: GetIntegrations -> QueryString
toQuery GetIntegrations' {Maybe Text
Text
apiId :: Text
nextToken :: Maybe Text
maxResults :: Maybe Text
$sel:apiId:GetIntegrations' :: GetIntegrations -> Text
$sel:nextToken:GetIntegrations' :: GetIntegrations -> Maybe Text
$sel:maxResults:GetIntegrations' :: GetIntegrations -> 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:/ 'newGetIntegrationsResponse' smart constructor.
data GetIntegrationsResponse = GetIntegrationsResponse'
  { -- | The elements from this collection.
    GetIntegrationsResponse -> Maybe [Integration]
items :: Prelude.Maybe [Integration],
    -- | The next page of elements from this collection. Not valid for the last
    -- element of the collection.
    GetIntegrationsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetIntegrationsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetIntegrationsResponse -> GetIntegrationsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetIntegrationsResponse -> GetIntegrationsResponse -> Bool
$c/= :: GetIntegrationsResponse -> GetIntegrationsResponse -> Bool
== :: GetIntegrationsResponse -> GetIntegrationsResponse -> Bool
$c== :: GetIntegrationsResponse -> GetIntegrationsResponse -> Bool
Prelude.Eq, ReadPrec [GetIntegrationsResponse]
ReadPrec GetIntegrationsResponse
Int -> ReadS GetIntegrationsResponse
ReadS [GetIntegrationsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetIntegrationsResponse]
$creadListPrec :: ReadPrec [GetIntegrationsResponse]
readPrec :: ReadPrec GetIntegrationsResponse
$creadPrec :: ReadPrec GetIntegrationsResponse
readList :: ReadS [GetIntegrationsResponse]
$creadList :: ReadS [GetIntegrationsResponse]
readsPrec :: Int -> ReadS GetIntegrationsResponse
$creadsPrec :: Int -> ReadS GetIntegrationsResponse
Prelude.Read, Int -> GetIntegrationsResponse -> ShowS
[GetIntegrationsResponse] -> ShowS
GetIntegrationsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetIntegrationsResponse] -> ShowS
$cshowList :: [GetIntegrationsResponse] -> ShowS
show :: GetIntegrationsResponse -> String
$cshow :: GetIntegrationsResponse -> String
showsPrec :: Int -> GetIntegrationsResponse -> ShowS
$cshowsPrec :: Int -> GetIntegrationsResponse -> ShowS
Prelude.Show, forall x. Rep GetIntegrationsResponse x -> GetIntegrationsResponse
forall x. GetIntegrationsResponse -> Rep GetIntegrationsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetIntegrationsResponse x -> GetIntegrationsResponse
$cfrom :: forall x. GetIntegrationsResponse -> Rep GetIntegrationsResponse x
Prelude.Generic)

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

-- | The elements from this collection.
getIntegrationsResponse_items :: Lens.Lens' GetIntegrationsResponse (Prelude.Maybe [Integration])
getIntegrationsResponse_items :: Lens' GetIntegrationsResponse (Maybe [Integration])
getIntegrationsResponse_items = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetIntegrationsResponse' {Maybe [Integration]
items :: Maybe [Integration]
$sel:items:GetIntegrationsResponse' :: GetIntegrationsResponse -> Maybe [Integration]
items} -> Maybe [Integration]
items) (\s :: GetIntegrationsResponse
s@GetIntegrationsResponse' {} Maybe [Integration]
a -> GetIntegrationsResponse
s {$sel:items:GetIntegrationsResponse' :: Maybe [Integration]
items = Maybe [Integration]
a} :: GetIntegrationsResponse) 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.
getIntegrationsResponse_nextToken :: Lens.Lens' GetIntegrationsResponse (Prelude.Maybe Prelude.Text)
getIntegrationsResponse_nextToken :: Lens' GetIntegrationsResponse (Maybe Text)
getIntegrationsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetIntegrationsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:GetIntegrationsResponse' :: GetIntegrationsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: GetIntegrationsResponse
s@GetIntegrationsResponse' {} Maybe Text
a -> GetIntegrationsResponse
s {$sel:nextToken:GetIntegrationsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: GetIntegrationsResponse)

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

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