{-# 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.GameLift.ListScripts
-- 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 script records for all Realtime scripts that are associated
-- with the Amazon Web Services account in use.
--
-- __Learn more__
--
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/realtime-intro.html Amazon GameLift Realtime Servers>
--
-- __Related actions__
--
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets All APIs by task>
--
-- This operation returns paginated results.
module Amazonka.GameLift.ListScripts
  ( -- * Creating a Request
    ListScripts (..),
    newListScripts,

    -- * Request Lenses
    listScripts_limit,
    listScripts_nextToken,

    -- * Destructuring the Response
    ListScriptsResponse (..),
    newListScriptsResponse,

    -- * Response Lenses
    listScriptsResponse_nextToken,
    listScriptsResponse_scripts,
    listScriptsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.GameLift.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newListScripts' smart constructor.
data ListScripts = ListScripts'
  { -- | The maximum number of results to return. Use this parameter with
    -- @NextToken@ to get results as a set of sequential pages.
    ListScripts -> Maybe Natural
limit :: Prelude.Maybe Prelude.Natural,
    -- | A token that indicates the start of the next sequential page of results.
    -- Use the token that is returned with a previous call to this operation.
    -- To start at the beginning of the result set, do not specify a value.
    ListScripts -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text
  }
  deriving (ListScripts -> ListScripts -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListScripts -> ListScripts -> Bool
$c/= :: ListScripts -> ListScripts -> Bool
== :: ListScripts -> ListScripts -> Bool
$c== :: ListScripts -> ListScripts -> Bool
Prelude.Eq, ReadPrec [ListScripts]
ReadPrec ListScripts
Int -> ReadS ListScripts
ReadS [ListScripts]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListScripts]
$creadListPrec :: ReadPrec [ListScripts]
readPrec :: ReadPrec ListScripts
$creadPrec :: ReadPrec ListScripts
readList :: ReadS [ListScripts]
$creadList :: ReadS [ListScripts]
readsPrec :: Int -> ReadS ListScripts
$creadsPrec :: Int -> ReadS ListScripts
Prelude.Read, Int -> ListScripts -> ShowS
[ListScripts] -> ShowS
ListScripts -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListScripts] -> ShowS
$cshowList :: [ListScripts] -> ShowS
show :: ListScripts -> String
$cshow :: ListScripts -> String
showsPrec :: Int -> ListScripts -> ShowS
$cshowsPrec :: Int -> ListScripts -> ShowS
Prelude.Show, forall x. Rep ListScripts x -> ListScripts
forall x. ListScripts -> Rep ListScripts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListScripts x -> ListScripts
$cfrom :: forall x. ListScripts -> Rep ListScripts x
Prelude.Generic)

-- |
-- Create a value of 'ListScripts' 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:
--
-- 'limit', 'listScripts_limit' - The maximum number of results to return. Use this parameter with
-- @NextToken@ to get results as a set of sequential pages.
--
-- 'nextToken', 'listScripts_nextToken' - A token that indicates the start of the next sequential page of results.
-- Use the token that is returned with a previous call to this operation.
-- To start at the beginning of the result set, do not specify a value.
newListScripts ::
  ListScripts
newListScripts :: ListScripts
newListScripts =
  ListScripts'
    { $sel:limit:ListScripts' :: Maybe Natural
limit = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListScripts' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of results to return. Use this parameter with
-- @NextToken@ to get results as a set of sequential pages.
listScripts_limit :: Lens.Lens' ListScripts (Prelude.Maybe Prelude.Natural)
listScripts_limit :: Lens' ListScripts (Maybe Natural)
listScripts_limit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListScripts' {Maybe Natural
limit :: Maybe Natural
$sel:limit:ListScripts' :: ListScripts -> Maybe Natural
limit} -> Maybe Natural
limit) (\s :: ListScripts
s@ListScripts' {} Maybe Natural
a -> ListScripts
s {$sel:limit:ListScripts' :: Maybe Natural
limit = Maybe Natural
a} :: ListScripts)

-- | A token that indicates the start of the next sequential page of results.
-- Use the token that is returned with a previous call to this operation.
-- To start at the beginning of the result set, do not specify a value.
listScripts_nextToken :: Lens.Lens' ListScripts (Prelude.Maybe Prelude.Text)
listScripts_nextToken :: Lens' ListScripts (Maybe Text)
listScripts_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListScripts' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListScripts' :: ListScripts -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListScripts
s@ListScripts' {} Maybe Text
a -> ListScripts
s {$sel:nextToken:ListScripts' :: Maybe Text
nextToken = Maybe Text
a} :: ListScripts)

instance Core.AWSPager ListScripts where
  page :: ListScripts -> AWSResponse ListScripts -> Maybe ListScripts
page ListScripts
rq AWSResponse ListScripts
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse ListScripts
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListScriptsResponse (Maybe Text)
listScriptsResponse_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 ListScripts
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListScriptsResponse (Maybe [Script])
listScriptsResponse_scripts
            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.$ ListScripts
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' ListScripts (Maybe Text)
listScripts_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse ListScripts
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' ListScriptsResponse (Maybe Text)
listScriptsResponse_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 ListScripts where
  type AWSResponse ListScripts = ListScriptsResponse
  request :: (Service -> Service) -> ListScripts -> Request ListScripts
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 ListScripts
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListScripts)))
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 [Script] -> Int -> ListScriptsResponse
ListScriptsResponse'
            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
"NextToken")
            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
"Scripts" 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 ListScripts where
  hashWithSalt :: Int -> ListScripts -> Int
hashWithSalt Int
_salt ListScripts' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
limit :: Maybe Natural
$sel:nextToken:ListScripts' :: ListScripts -> Maybe Text
$sel:limit:ListScripts' :: ListScripts -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
limit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken

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

instance Data.ToHeaders ListScripts where
  toHeaders :: ListScripts -> 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
"GameLift.ListScripts" :: 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 ListScripts where
  toJSON :: ListScripts -> Value
toJSON ListScripts' {Maybe Natural
Maybe Text
nextToken :: Maybe Text
limit :: Maybe Natural
$sel:nextToken:ListScripts' :: ListScripts -> Maybe Text
$sel:limit:ListScripts' :: ListScripts -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Limit" 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
limit,
            (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 ListScripts where
  toPath :: ListScripts -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newListScriptsResponse' smart constructor.
data ListScriptsResponse = ListScriptsResponse'
  { -- | A token that indicates where to resume retrieving results on the next
    -- call to this operation. If no token is returned, these results represent
    -- the end of the list.
    ListScriptsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A set of properties describing the requested script.
    ListScriptsResponse -> Maybe [Script]
scripts :: Prelude.Maybe [Script],
    -- | The response's http status code.
    ListScriptsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListScriptsResponse -> ListScriptsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListScriptsResponse -> ListScriptsResponse -> Bool
$c/= :: ListScriptsResponse -> ListScriptsResponse -> Bool
== :: ListScriptsResponse -> ListScriptsResponse -> Bool
$c== :: ListScriptsResponse -> ListScriptsResponse -> Bool
Prelude.Eq, ReadPrec [ListScriptsResponse]
ReadPrec ListScriptsResponse
Int -> ReadS ListScriptsResponse
ReadS [ListScriptsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListScriptsResponse]
$creadListPrec :: ReadPrec [ListScriptsResponse]
readPrec :: ReadPrec ListScriptsResponse
$creadPrec :: ReadPrec ListScriptsResponse
readList :: ReadS [ListScriptsResponse]
$creadList :: ReadS [ListScriptsResponse]
readsPrec :: Int -> ReadS ListScriptsResponse
$creadsPrec :: Int -> ReadS ListScriptsResponse
Prelude.Read, Int -> ListScriptsResponse -> ShowS
[ListScriptsResponse] -> ShowS
ListScriptsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListScriptsResponse] -> ShowS
$cshowList :: [ListScriptsResponse] -> ShowS
show :: ListScriptsResponse -> String
$cshow :: ListScriptsResponse -> String
showsPrec :: Int -> ListScriptsResponse -> ShowS
$cshowsPrec :: Int -> ListScriptsResponse -> ShowS
Prelude.Show, forall x. Rep ListScriptsResponse x -> ListScriptsResponse
forall x. ListScriptsResponse -> Rep ListScriptsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListScriptsResponse x -> ListScriptsResponse
$cfrom :: forall x. ListScriptsResponse -> Rep ListScriptsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListScriptsResponse' 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', 'listScriptsResponse_nextToken' - A token that indicates where to resume retrieving results on the next
-- call to this operation. If no token is returned, these results represent
-- the end of the list.
--
-- 'scripts', 'listScriptsResponse_scripts' - A set of properties describing the requested script.
--
-- 'httpStatus', 'listScriptsResponse_httpStatus' - The response's http status code.
newListScriptsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListScriptsResponse
newListScriptsResponse :: Int -> ListScriptsResponse
newListScriptsResponse Int
pHttpStatus_ =
  ListScriptsResponse'
    { $sel:nextToken:ListScriptsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:scripts:ListScriptsResponse' :: Maybe [Script]
scripts = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListScriptsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A token that indicates where to resume retrieving results on the next
-- call to this operation. If no token is returned, these results represent
-- the end of the list.
listScriptsResponse_nextToken :: Lens.Lens' ListScriptsResponse (Prelude.Maybe Prelude.Text)
listScriptsResponse_nextToken :: Lens' ListScriptsResponse (Maybe Text)
listScriptsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListScriptsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListScriptsResponse' :: ListScriptsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListScriptsResponse
s@ListScriptsResponse' {} Maybe Text
a -> ListScriptsResponse
s {$sel:nextToken:ListScriptsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListScriptsResponse)

-- | A set of properties describing the requested script.
listScriptsResponse_scripts :: Lens.Lens' ListScriptsResponse (Prelude.Maybe [Script])
listScriptsResponse_scripts :: Lens' ListScriptsResponse (Maybe [Script])
listScriptsResponse_scripts = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListScriptsResponse' {Maybe [Script]
scripts :: Maybe [Script]
$sel:scripts:ListScriptsResponse' :: ListScriptsResponse -> Maybe [Script]
scripts} -> Maybe [Script]
scripts) (\s :: ListScriptsResponse
s@ListScriptsResponse' {} Maybe [Script]
a -> ListScriptsResponse
s {$sel:scripts:ListScriptsResponse' :: Maybe [Script]
scripts = Maybe [Script]
a} :: ListScriptsResponse) 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.
listScriptsResponse_httpStatus :: Lens.Lens' ListScriptsResponse Prelude.Int
listScriptsResponse_httpStatus :: Lens' ListScriptsResponse Int
listScriptsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListScriptsResponse' {Int
httpStatus :: Int
$sel:httpStatus:ListScriptsResponse' :: ListScriptsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ListScriptsResponse
s@ListScriptsResponse' {} Int
a -> ListScriptsResponse
s {$sel:httpStatus:ListScriptsResponse' :: Int
httpStatus = Int
a} :: ListScriptsResponse)

instance Prelude.NFData ListScriptsResponse where
  rnf :: ListScriptsResponse -> ()
rnf ListScriptsResponse' {Int
Maybe [Script]
Maybe Text
httpStatus :: Int
scripts :: Maybe [Script]
nextToken :: Maybe Text
$sel:httpStatus:ListScriptsResponse' :: ListScriptsResponse -> Int
$sel:scripts:ListScriptsResponse' :: ListScriptsResponse -> Maybe [Script]
$sel:nextToken:ListScriptsResponse' :: ListScriptsResponse -> Maybe Text
..} =
    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 Maybe [Script]
scripts
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus