{-# 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.SearchGameSessions
-- 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 all active game sessions that match a set of search criteria
-- and sorts them into a specified order.
--
-- This operation is not designed to be continually called to track game
-- session status. This practice can cause you to exceed your API limit,
-- which results in errors. Instead, you must configure configure an Amazon
-- Simple Notification Service (SNS) topic to receive notifications from
-- FlexMatch or queues. Continuously polling game session status with
-- @DescribeGameSessions@ should only be used for games in development with
-- low game session usage.
--
-- When searching for game sessions, you specify exactly where you want to
-- search and provide a search filter expression, a sort expression, or
-- both. A search request can search only one fleet, but it can search all
-- of a fleet\'s locations.
--
-- This operation can be used in the following ways:
--
-- -   To search all game sessions that are currently running on all
--     locations in a fleet, provide a fleet or alias ID. This approach
--     returns game sessions in the fleet\'s home Region and all remote
--     locations that fit the search criteria.
--
-- -   To search all game sessions that are currently running on a specific
--     fleet location, provide a fleet or alias ID and a location name. For
--     location, you can specify a fleet\'s home Region or any remote
--     location.
--
-- Use the pagination parameters to retrieve results as a set of sequential
-- pages.
--
-- If successful, a @GameSession@ object is returned for each game session
-- that matches the request. Search finds game sessions that are in
-- @ACTIVE@ status only. To retrieve information on game sessions in other
-- statuses, use
-- <https://docs.aws.amazon.com/gamelift/latest/apireference/API_DescribeGameSessions.html DescribeGameSessions>
-- .
--
-- You can search or sort by the following game session attributes:
--
-- -   __gameSessionId__ -- A unique identifier for the game session. You
--     can use either a @GameSessionId@ or @GameSessionArn@ value.
--
-- -   __gameSessionName__ -- Name assigned to a game session. Game session
--     names do not need to be unique to a game session.
--
-- -   __gameSessionProperties__ -- Custom data defined in a game
--     session\'s @GameProperty@ parameter. @GameProperty@ values are
--     stored as key:value pairs; the filter expression must indicate the
--     key and a string to search the data values for. For example, to
--     search for game sessions with custom data containing the key:value
--     pair \"gameMode:brawl\", specify the following:
--     @gameSessionProperties.gameMode = \"brawl\"@. All custom data values
--     are searched as strings.
--
-- -   __maximumSessions__ -- Maximum number of player sessions allowed for
--     a game session.
--
-- -   __creationTimeMillis__ -- Value indicating when a game session was
--     created. It is expressed in Unix time as milliseconds.
--
-- -   __playerSessionCount__ -- Number of players currently connected to a
--     game session. This value changes rapidly as players join the session
--     or drop out.
--
-- -   __hasAvailablePlayerSessions__ -- Boolean value indicating whether a
--     game session has reached its maximum number of players. It is highly
--     recommended that all search requests include this filter attribute
--     to optimize search performance and return only sessions that players
--     can join.
--
-- Returned values for @playerSessionCount@ and
-- @hasAvailablePlayerSessions@ change quickly as players join sessions and
-- others drop out. Results should be considered a snapshot in time. Be
-- sure to refresh search results often, and handle sessions that fill up
-- before a player can join.
--
-- <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.SearchGameSessions
  ( -- * Creating a Request
    SearchGameSessions (..),
    newSearchGameSessions,

    -- * Request Lenses
    searchGameSessions_aliasId,
    searchGameSessions_filterExpression,
    searchGameSessions_fleetId,
    searchGameSessions_limit,
    searchGameSessions_location,
    searchGameSessions_nextToken,
    searchGameSessions_sortExpression,

    -- * Destructuring the Response
    SearchGameSessionsResponse (..),
    newSearchGameSessionsResponse,

    -- * Response Lenses
    searchGameSessionsResponse_gameSessions,
    searchGameSessionsResponse_nextToken,
    searchGameSessionsResponse_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:/ 'newSearchGameSessions' smart constructor.
data SearchGameSessions = SearchGameSessions'
  { -- | A unique identifier for the alias associated with the fleet to search
    -- for active game sessions. You can use either the alias ID or ARN value.
    -- Each request must reference either a fleet ID or alias ID, but not both.
    SearchGameSessions -> Maybe Text
aliasId :: Prelude.Maybe Prelude.Text,
    -- | String containing the search criteria for the session search. If no
    -- filter expression is included, the request returns results for all game
    -- sessions in the fleet that are in @ACTIVE@ status.
    --
    -- A filter expression can contain one or multiple conditions. Each
    -- condition consists of the following:
    --
    -- -   __Operand__ -- Name of a game session attribute. Valid values are
    --     @gameSessionName@, @gameSessionId@, @gameSessionProperties@,
    --     @maximumSessions@, @creationTimeMillis@, @playerSessionCount@,
    --     @hasAvailablePlayerSessions@.
    --
    -- -   __Comparator__ -- Valid comparators are: @=@, @\<>@, @\<@, @>@,
    --     @\<=@, @>=@.
    --
    -- -   __Value__ -- Value to be searched for. Values may be numbers,
    --     boolean values (true\/false) or strings depending on the operand.
    --     String values are case sensitive and must be enclosed in single
    --     quotes. Special characters must be escaped. Boolean and string
    --     values can only be used with the comparators @=@ and @\<>@. For
    --     example, the following filter expression searches on
    --     @gameSessionName@:
    --     \"@FilterExpression\": \"gameSessionName = \'Matt\\\\\'s Awesome Game 1\'\"@.
    --
    -- To chain multiple conditions in a single expression, use the logical
    -- keywords @AND@, @OR@, and @NOT@ and parentheses as needed. For example:
    -- @x AND y AND NOT z@, @NOT (x OR y)@.
    --
    -- Session search evaluates conditions from left to right using the
    -- following precedence rules:
    --
    -- 1.  @=@, @\<>@, @\<@, @>@, @\<=@, @>=@
    --
    -- 2.  Parentheses
    --
    -- 3.  NOT
    --
    -- 4.  AND
    --
    -- 5.  OR
    --
    -- For example, this filter expression retrieves game sessions hosting at
    -- least ten players that have an open player slot:
    -- @\"maximumSessions>=10 AND hasAvailablePlayerSessions=true\"@.
    SearchGameSessions -> Maybe Text
filterExpression :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for the fleet to search for active game sessions.
    -- You can use either the fleet ID or ARN value. Each request must
    -- reference either a fleet ID or alias ID, but not both.
    SearchGameSessions -> Maybe Text
fleetId :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of results to return. Use this parameter with
    -- @NextToken@ to get results as a set of sequential pages. The maximum
    -- number of results returned is 20, even if this value is not set or is
    -- set higher than 20.
    SearchGameSessions -> Maybe Natural
limit :: Prelude.Maybe Prelude.Natural,
    -- | A fleet location to search for game sessions. You can specify a fleet\'s
    -- home Region or a remote location. Use the Amazon Web Services Region
    -- code format, such as @us-west-2@.
    SearchGameSessions -> Maybe Text
location :: Prelude.Maybe Prelude.Text,
    -- | 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.
    SearchGameSessions -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | Instructions on how to sort the search results. If no sort expression is
    -- included, the request returns results in random order. A sort expression
    -- consists of the following elements:
    --
    -- -   __Operand__ -- Name of a game session attribute. Valid values are
    --     @gameSessionName@, @gameSessionId@, @gameSessionProperties@,
    --     @maximumSessions@, @creationTimeMillis@, @playerSessionCount@,
    --     @hasAvailablePlayerSessions@.
    --
    -- -   __Order__ -- Valid sort orders are @ASC@ (ascending) and @DESC@
    --     (descending).
    --
    -- For example, this sort expression returns the oldest active sessions
    -- first: @\"SortExpression\": \"creationTimeMillis ASC\"@. Results with a
    -- null value for the sort operand are returned at the end of the list.
    SearchGameSessions -> Maybe Text
sortExpression :: Prelude.Maybe Prelude.Text
  }
  deriving (SearchGameSessions -> SearchGameSessions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SearchGameSessions -> SearchGameSessions -> Bool
$c/= :: SearchGameSessions -> SearchGameSessions -> Bool
== :: SearchGameSessions -> SearchGameSessions -> Bool
$c== :: SearchGameSessions -> SearchGameSessions -> Bool
Prelude.Eq, ReadPrec [SearchGameSessions]
ReadPrec SearchGameSessions
Int -> ReadS SearchGameSessions
ReadS [SearchGameSessions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SearchGameSessions]
$creadListPrec :: ReadPrec [SearchGameSessions]
readPrec :: ReadPrec SearchGameSessions
$creadPrec :: ReadPrec SearchGameSessions
readList :: ReadS [SearchGameSessions]
$creadList :: ReadS [SearchGameSessions]
readsPrec :: Int -> ReadS SearchGameSessions
$creadsPrec :: Int -> ReadS SearchGameSessions
Prelude.Read, Int -> SearchGameSessions -> ShowS
[SearchGameSessions] -> ShowS
SearchGameSessions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SearchGameSessions] -> ShowS
$cshowList :: [SearchGameSessions] -> ShowS
show :: SearchGameSessions -> String
$cshow :: SearchGameSessions -> String
showsPrec :: Int -> SearchGameSessions -> ShowS
$cshowsPrec :: Int -> SearchGameSessions -> ShowS
Prelude.Show, forall x. Rep SearchGameSessions x -> SearchGameSessions
forall x. SearchGameSessions -> Rep SearchGameSessions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SearchGameSessions x -> SearchGameSessions
$cfrom :: forall x. SearchGameSessions -> Rep SearchGameSessions x
Prelude.Generic)

-- |
-- Create a value of 'SearchGameSessions' 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:
--
-- 'aliasId', 'searchGameSessions_aliasId' - A unique identifier for the alias associated with the fleet to search
-- for active game sessions. You can use either the alias ID or ARN value.
-- Each request must reference either a fleet ID or alias ID, but not both.
--
-- 'filterExpression', 'searchGameSessions_filterExpression' - String containing the search criteria for the session search. If no
-- filter expression is included, the request returns results for all game
-- sessions in the fleet that are in @ACTIVE@ status.
--
-- A filter expression can contain one or multiple conditions. Each
-- condition consists of the following:
--
-- -   __Operand__ -- Name of a game session attribute. Valid values are
--     @gameSessionName@, @gameSessionId@, @gameSessionProperties@,
--     @maximumSessions@, @creationTimeMillis@, @playerSessionCount@,
--     @hasAvailablePlayerSessions@.
--
-- -   __Comparator__ -- Valid comparators are: @=@, @\<>@, @\<@, @>@,
--     @\<=@, @>=@.
--
-- -   __Value__ -- Value to be searched for. Values may be numbers,
--     boolean values (true\/false) or strings depending on the operand.
--     String values are case sensitive and must be enclosed in single
--     quotes. Special characters must be escaped. Boolean and string
--     values can only be used with the comparators @=@ and @\<>@. For
--     example, the following filter expression searches on
--     @gameSessionName@:
--     \"@FilterExpression\": \"gameSessionName = \'Matt\\\\\'s Awesome Game 1\'\"@.
--
-- To chain multiple conditions in a single expression, use the logical
-- keywords @AND@, @OR@, and @NOT@ and parentheses as needed. For example:
-- @x AND y AND NOT z@, @NOT (x OR y)@.
--
-- Session search evaluates conditions from left to right using the
-- following precedence rules:
--
-- 1.  @=@, @\<>@, @\<@, @>@, @\<=@, @>=@
--
-- 2.  Parentheses
--
-- 3.  NOT
--
-- 4.  AND
--
-- 5.  OR
--
-- For example, this filter expression retrieves game sessions hosting at
-- least ten players that have an open player slot:
-- @\"maximumSessions>=10 AND hasAvailablePlayerSessions=true\"@.
--
-- 'fleetId', 'searchGameSessions_fleetId' - A unique identifier for the fleet to search for active game sessions.
-- You can use either the fleet ID or ARN value. Each request must
-- reference either a fleet ID or alias ID, but not both.
--
-- 'limit', 'searchGameSessions_limit' - The maximum number of results to return. Use this parameter with
-- @NextToken@ to get results as a set of sequential pages. The maximum
-- number of results returned is 20, even if this value is not set or is
-- set higher than 20.
--
-- 'location', 'searchGameSessions_location' - A fleet location to search for game sessions. You can specify a fleet\'s
-- home Region or a remote location. Use the Amazon Web Services Region
-- code format, such as @us-west-2@.
--
-- 'nextToken', 'searchGameSessions_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.
--
-- 'sortExpression', 'searchGameSessions_sortExpression' - Instructions on how to sort the search results. If no sort expression is
-- included, the request returns results in random order. A sort expression
-- consists of the following elements:
--
-- -   __Operand__ -- Name of a game session attribute. Valid values are
--     @gameSessionName@, @gameSessionId@, @gameSessionProperties@,
--     @maximumSessions@, @creationTimeMillis@, @playerSessionCount@,
--     @hasAvailablePlayerSessions@.
--
-- -   __Order__ -- Valid sort orders are @ASC@ (ascending) and @DESC@
--     (descending).
--
-- For example, this sort expression returns the oldest active sessions
-- first: @\"SortExpression\": \"creationTimeMillis ASC\"@. Results with a
-- null value for the sort operand are returned at the end of the list.
newSearchGameSessions ::
  SearchGameSessions
newSearchGameSessions :: SearchGameSessions
newSearchGameSessions =
  SearchGameSessions'
    { $sel:aliasId:SearchGameSessions' :: Maybe Text
aliasId = forall a. Maybe a
Prelude.Nothing,
      $sel:filterExpression:SearchGameSessions' :: Maybe Text
filterExpression = forall a. Maybe a
Prelude.Nothing,
      $sel:fleetId:SearchGameSessions' :: Maybe Text
fleetId = forall a. Maybe a
Prelude.Nothing,
      $sel:limit:SearchGameSessions' :: Maybe Natural
limit = forall a. Maybe a
Prelude.Nothing,
      $sel:location:SearchGameSessions' :: Maybe Text
location = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:SearchGameSessions' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:sortExpression:SearchGameSessions' :: Maybe Text
sortExpression = forall a. Maybe a
Prelude.Nothing
    }

-- | A unique identifier for the alias associated with the fleet to search
-- for active game sessions. You can use either the alias ID or ARN value.
-- Each request must reference either a fleet ID or alias ID, but not both.
searchGameSessions_aliasId :: Lens.Lens' SearchGameSessions (Prelude.Maybe Prelude.Text)
searchGameSessions_aliasId :: Lens' SearchGameSessions (Maybe Text)
searchGameSessions_aliasId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessions' {Maybe Text
aliasId :: Maybe Text
$sel:aliasId:SearchGameSessions' :: SearchGameSessions -> Maybe Text
aliasId} -> Maybe Text
aliasId) (\s :: SearchGameSessions
s@SearchGameSessions' {} Maybe Text
a -> SearchGameSessions
s {$sel:aliasId:SearchGameSessions' :: Maybe Text
aliasId = Maybe Text
a} :: SearchGameSessions)

-- | String containing the search criteria for the session search. If no
-- filter expression is included, the request returns results for all game
-- sessions in the fleet that are in @ACTIVE@ status.
--
-- A filter expression can contain one or multiple conditions. Each
-- condition consists of the following:
--
-- -   __Operand__ -- Name of a game session attribute. Valid values are
--     @gameSessionName@, @gameSessionId@, @gameSessionProperties@,
--     @maximumSessions@, @creationTimeMillis@, @playerSessionCount@,
--     @hasAvailablePlayerSessions@.
--
-- -   __Comparator__ -- Valid comparators are: @=@, @\<>@, @\<@, @>@,
--     @\<=@, @>=@.
--
-- -   __Value__ -- Value to be searched for. Values may be numbers,
--     boolean values (true\/false) or strings depending on the operand.
--     String values are case sensitive and must be enclosed in single
--     quotes. Special characters must be escaped. Boolean and string
--     values can only be used with the comparators @=@ and @\<>@. For
--     example, the following filter expression searches on
--     @gameSessionName@:
--     \"@FilterExpression\": \"gameSessionName = \'Matt\\\\\'s Awesome Game 1\'\"@.
--
-- To chain multiple conditions in a single expression, use the logical
-- keywords @AND@, @OR@, and @NOT@ and parentheses as needed. For example:
-- @x AND y AND NOT z@, @NOT (x OR y)@.
--
-- Session search evaluates conditions from left to right using the
-- following precedence rules:
--
-- 1.  @=@, @\<>@, @\<@, @>@, @\<=@, @>=@
--
-- 2.  Parentheses
--
-- 3.  NOT
--
-- 4.  AND
--
-- 5.  OR
--
-- For example, this filter expression retrieves game sessions hosting at
-- least ten players that have an open player slot:
-- @\"maximumSessions>=10 AND hasAvailablePlayerSessions=true\"@.
searchGameSessions_filterExpression :: Lens.Lens' SearchGameSessions (Prelude.Maybe Prelude.Text)
searchGameSessions_filterExpression :: Lens' SearchGameSessions (Maybe Text)
searchGameSessions_filterExpression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessions' {Maybe Text
filterExpression :: Maybe Text
$sel:filterExpression:SearchGameSessions' :: SearchGameSessions -> Maybe Text
filterExpression} -> Maybe Text
filterExpression) (\s :: SearchGameSessions
s@SearchGameSessions' {} Maybe Text
a -> SearchGameSessions
s {$sel:filterExpression:SearchGameSessions' :: Maybe Text
filterExpression = Maybe Text
a} :: SearchGameSessions)

-- | A unique identifier for the fleet to search for active game sessions.
-- You can use either the fleet ID or ARN value. Each request must
-- reference either a fleet ID or alias ID, but not both.
searchGameSessions_fleetId :: Lens.Lens' SearchGameSessions (Prelude.Maybe Prelude.Text)
searchGameSessions_fleetId :: Lens' SearchGameSessions (Maybe Text)
searchGameSessions_fleetId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessions' {Maybe Text
fleetId :: Maybe Text
$sel:fleetId:SearchGameSessions' :: SearchGameSessions -> Maybe Text
fleetId} -> Maybe Text
fleetId) (\s :: SearchGameSessions
s@SearchGameSessions' {} Maybe Text
a -> SearchGameSessions
s {$sel:fleetId:SearchGameSessions' :: Maybe Text
fleetId = Maybe Text
a} :: SearchGameSessions)

-- | The maximum number of results to return. Use this parameter with
-- @NextToken@ to get results as a set of sequential pages. The maximum
-- number of results returned is 20, even if this value is not set or is
-- set higher than 20.
searchGameSessions_limit :: Lens.Lens' SearchGameSessions (Prelude.Maybe Prelude.Natural)
searchGameSessions_limit :: Lens' SearchGameSessions (Maybe Natural)
searchGameSessions_limit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessions' {Maybe Natural
limit :: Maybe Natural
$sel:limit:SearchGameSessions' :: SearchGameSessions -> Maybe Natural
limit} -> Maybe Natural
limit) (\s :: SearchGameSessions
s@SearchGameSessions' {} Maybe Natural
a -> SearchGameSessions
s {$sel:limit:SearchGameSessions' :: Maybe Natural
limit = Maybe Natural
a} :: SearchGameSessions)

-- | A fleet location to search for game sessions. You can specify a fleet\'s
-- home Region or a remote location. Use the Amazon Web Services Region
-- code format, such as @us-west-2@.
searchGameSessions_location :: Lens.Lens' SearchGameSessions (Prelude.Maybe Prelude.Text)
searchGameSessions_location :: Lens' SearchGameSessions (Maybe Text)
searchGameSessions_location = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessions' {Maybe Text
location :: Maybe Text
$sel:location:SearchGameSessions' :: SearchGameSessions -> Maybe Text
location} -> Maybe Text
location) (\s :: SearchGameSessions
s@SearchGameSessions' {} Maybe Text
a -> SearchGameSessions
s {$sel:location:SearchGameSessions' :: Maybe Text
location = Maybe Text
a} :: SearchGameSessions)

-- | 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.
searchGameSessions_nextToken :: Lens.Lens' SearchGameSessions (Prelude.Maybe Prelude.Text)
searchGameSessions_nextToken :: Lens' SearchGameSessions (Maybe Text)
searchGameSessions_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessions' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:SearchGameSessions' :: SearchGameSessions -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: SearchGameSessions
s@SearchGameSessions' {} Maybe Text
a -> SearchGameSessions
s {$sel:nextToken:SearchGameSessions' :: Maybe Text
nextToken = Maybe Text
a} :: SearchGameSessions)

-- | Instructions on how to sort the search results. If no sort expression is
-- included, the request returns results in random order. A sort expression
-- consists of the following elements:
--
-- -   __Operand__ -- Name of a game session attribute. Valid values are
--     @gameSessionName@, @gameSessionId@, @gameSessionProperties@,
--     @maximumSessions@, @creationTimeMillis@, @playerSessionCount@,
--     @hasAvailablePlayerSessions@.
--
-- -   __Order__ -- Valid sort orders are @ASC@ (ascending) and @DESC@
--     (descending).
--
-- For example, this sort expression returns the oldest active sessions
-- first: @\"SortExpression\": \"creationTimeMillis ASC\"@. Results with a
-- null value for the sort operand are returned at the end of the list.
searchGameSessions_sortExpression :: Lens.Lens' SearchGameSessions (Prelude.Maybe Prelude.Text)
searchGameSessions_sortExpression :: Lens' SearchGameSessions (Maybe Text)
searchGameSessions_sortExpression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessions' {Maybe Text
sortExpression :: Maybe Text
$sel:sortExpression:SearchGameSessions' :: SearchGameSessions -> Maybe Text
sortExpression} -> Maybe Text
sortExpression) (\s :: SearchGameSessions
s@SearchGameSessions' {} Maybe Text
a -> SearchGameSessions
s {$sel:sortExpression:SearchGameSessions' :: Maybe Text
sortExpression = Maybe Text
a} :: SearchGameSessions)

instance Core.AWSPager SearchGameSessions where
  page :: SearchGameSessions
-> AWSResponse SearchGameSessions -> Maybe SearchGameSessions
page SearchGameSessions
rq AWSResponse SearchGameSessions
rs
    | forall a. AWSTruncated a => a -> Bool
Core.stop
        ( AWSResponse SearchGameSessions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' SearchGameSessionsResponse (Maybe Text)
searchGameSessionsResponse_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 SearchGameSessions
rs
            forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' SearchGameSessionsResponse (Maybe [GameSession])
searchGameSessionsResponse_gameSessions
            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.$ SearchGameSessions
rq
          forall a b. a -> (a -> b) -> b
Prelude.& Lens' SearchGameSessions (Maybe Text)
searchGameSessions_nextToken
          forall s t a b. ASetter s t a b -> b -> s -> t
Lens..~ AWSResponse SearchGameSessions
rs
          forall s a. s -> Getting (First a) s a -> Maybe a
Lens.^? Lens' SearchGameSessionsResponse (Maybe Text)
searchGameSessionsResponse_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 SearchGameSessions where
  type
    AWSResponse SearchGameSessions =
      SearchGameSessionsResponse
  request :: (Service -> Service)
-> SearchGameSessions -> Request SearchGameSessions
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 SearchGameSessions
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SearchGameSessions)))
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 [GameSession]
-> Maybe Text -> Int -> SearchGameSessionsResponse
SearchGameSessionsResponse'
            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
"GameSessions" 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 SearchGameSessions where
  hashWithSalt :: Int -> SearchGameSessions -> Int
hashWithSalt Int
_salt SearchGameSessions' {Maybe Natural
Maybe Text
sortExpression :: Maybe Text
nextToken :: Maybe Text
location :: Maybe Text
limit :: Maybe Natural
fleetId :: Maybe Text
filterExpression :: Maybe Text
aliasId :: Maybe Text
$sel:sortExpression:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:nextToken:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:location:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:limit:SearchGameSessions' :: SearchGameSessions -> Maybe Natural
$sel:fleetId:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:filterExpression:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:aliasId:SearchGameSessions' :: SearchGameSessions -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
aliasId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
filterExpression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
fleetId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
limit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
location
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sortExpression

instance Prelude.NFData SearchGameSessions where
  rnf :: SearchGameSessions -> ()
rnf SearchGameSessions' {Maybe Natural
Maybe Text
sortExpression :: Maybe Text
nextToken :: Maybe Text
location :: Maybe Text
limit :: Maybe Natural
fleetId :: Maybe Text
filterExpression :: Maybe Text
aliasId :: Maybe Text
$sel:sortExpression:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:nextToken:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:location:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:limit:SearchGameSessions' :: SearchGameSessions -> Maybe Natural
$sel:fleetId:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:filterExpression:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:aliasId:SearchGameSessions' :: SearchGameSessions -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
aliasId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
filterExpression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
fleetId
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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
location
      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 Maybe Text
sortExpression

instance Data.ToHeaders SearchGameSessions where
  toHeaders :: SearchGameSessions -> 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.SearchGameSessions" ::
                          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 SearchGameSessions where
  toJSON :: SearchGameSessions -> Value
toJSON SearchGameSessions' {Maybe Natural
Maybe Text
sortExpression :: Maybe Text
nextToken :: Maybe Text
location :: Maybe Text
limit :: Maybe Natural
fleetId :: Maybe Text
filterExpression :: Maybe Text
aliasId :: Maybe Text
$sel:sortExpression:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:nextToken:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:location:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:limit:SearchGameSessions' :: SearchGameSessions -> Maybe Natural
$sel:fleetId:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:filterExpression:SearchGameSessions' :: SearchGameSessions -> Maybe Text
$sel:aliasId:SearchGameSessions' :: SearchGameSessions -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AliasId" 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
aliasId,
            (Key
"FilterExpression" 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
filterExpression,
            (Key
"FleetId" 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
fleetId,
            (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
"Location" 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
location,
            (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,
            (Key
"SortExpression" 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
sortExpression
          ]
      )

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

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

-- | /See:/ 'newSearchGameSessionsResponse' smart constructor.
data SearchGameSessionsResponse = SearchGameSessionsResponse'
  { -- | A collection of objects containing game session properties for each
    -- session that matches the request.
    SearchGameSessionsResponse -> Maybe [GameSession]
gameSessions :: Prelude.Maybe [GameSession],
    -- | 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.
    SearchGameSessionsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    SearchGameSessionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SearchGameSessionsResponse -> SearchGameSessionsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SearchGameSessionsResponse -> SearchGameSessionsResponse -> Bool
$c/= :: SearchGameSessionsResponse -> SearchGameSessionsResponse -> Bool
== :: SearchGameSessionsResponse -> SearchGameSessionsResponse -> Bool
$c== :: SearchGameSessionsResponse -> SearchGameSessionsResponse -> Bool
Prelude.Eq, ReadPrec [SearchGameSessionsResponse]
ReadPrec SearchGameSessionsResponse
Int -> ReadS SearchGameSessionsResponse
ReadS [SearchGameSessionsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SearchGameSessionsResponse]
$creadListPrec :: ReadPrec [SearchGameSessionsResponse]
readPrec :: ReadPrec SearchGameSessionsResponse
$creadPrec :: ReadPrec SearchGameSessionsResponse
readList :: ReadS [SearchGameSessionsResponse]
$creadList :: ReadS [SearchGameSessionsResponse]
readsPrec :: Int -> ReadS SearchGameSessionsResponse
$creadsPrec :: Int -> ReadS SearchGameSessionsResponse
Prelude.Read, Int -> SearchGameSessionsResponse -> ShowS
[SearchGameSessionsResponse] -> ShowS
SearchGameSessionsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SearchGameSessionsResponse] -> ShowS
$cshowList :: [SearchGameSessionsResponse] -> ShowS
show :: SearchGameSessionsResponse -> String
$cshow :: SearchGameSessionsResponse -> String
showsPrec :: Int -> SearchGameSessionsResponse -> ShowS
$cshowsPrec :: Int -> SearchGameSessionsResponse -> ShowS
Prelude.Show, forall x.
Rep SearchGameSessionsResponse x -> SearchGameSessionsResponse
forall x.
SearchGameSessionsResponse -> Rep SearchGameSessionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SearchGameSessionsResponse x -> SearchGameSessionsResponse
$cfrom :: forall x.
SearchGameSessionsResponse -> Rep SearchGameSessionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'SearchGameSessionsResponse' 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:
--
-- 'gameSessions', 'searchGameSessionsResponse_gameSessions' - A collection of objects containing game session properties for each
-- session that matches the request.
--
-- 'nextToken', 'searchGameSessionsResponse_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.
--
-- 'httpStatus', 'searchGameSessionsResponse_httpStatus' - The response's http status code.
newSearchGameSessionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SearchGameSessionsResponse
newSearchGameSessionsResponse :: Int -> SearchGameSessionsResponse
newSearchGameSessionsResponse Int
pHttpStatus_ =
  SearchGameSessionsResponse'
    { $sel:gameSessions:SearchGameSessionsResponse' :: Maybe [GameSession]
gameSessions =
        forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:SearchGameSessionsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SearchGameSessionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A collection of objects containing game session properties for each
-- session that matches the request.
searchGameSessionsResponse_gameSessions :: Lens.Lens' SearchGameSessionsResponse (Prelude.Maybe [GameSession])
searchGameSessionsResponse_gameSessions :: Lens' SearchGameSessionsResponse (Maybe [GameSession])
searchGameSessionsResponse_gameSessions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessionsResponse' {Maybe [GameSession]
gameSessions :: Maybe [GameSession]
$sel:gameSessions:SearchGameSessionsResponse' :: SearchGameSessionsResponse -> Maybe [GameSession]
gameSessions} -> Maybe [GameSession]
gameSessions) (\s :: SearchGameSessionsResponse
s@SearchGameSessionsResponse' {} Maybe [GameSession]
a -> SearchGameSessionsResponse
s {$sel:gameSessions:SearchGameSessionsResponse' :: Maybe [GameSession]
gameSessions = Maybe [GameSession]
a} :: SearchGameSessionsResponse) 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

-- | 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.
searchGameSessionsResponse_nextToken :: Lens.Lens' SearchGameSessionsResponse (Prelude.Maybe Prelude.Text)
searchGameSessionsResponse_nextToken :: Lens' SearchGameSessionsResponse (Maybe Text)
searchGameSessionsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SearchGameSessionsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:SearchGameSessionsResponse' :: SearchGameSessionsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: SearchGameSessionsResponse
s@SearchGameSessionsResponse' {} Maybe Text
a -> SearchGameSessionsResponse
s {$sel:nextToken:SearchGameSessionsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: SearchGameSessionsResponse)

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

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