{-# 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.AcceptMatch
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Registers a player\'s acceptance or rejection of a proposed FlexMatch
-- match. A matchmaking configuration may require player acceptance; if so,
-- then matches built with that configuration cannot be completed unless
-- all players accept the proposed match within a specified time limit.
--
-- When FlexMatch builds a match, all the matchmaking tickets involved in
-- the proposed match are placed into status @REQUIRES_ACCEPTANCE@. This is
-- a trigger for your game to get acceptance from all players in the
-- ticket. Acceptances are only valid for tickets when they are in this
-- status; all other acceptances result in an error.
--
-- To register acceptance, specify the ticket ID, a response, and one or
-- more players. Once all players have registered acceptance, the
-- matchmaking tickets advance to status @PLACING@, where a new game
-- session is created for the match.
--
-- If any player rejects the match, or if acceptances are not received
-- before a specified timeout, the proposed match is dropped. The
-- matchmaking tickets are then handled in one of two ways: For tickets
-- where one or more players rejected the match, the ticket status is
-- returned to @SEARCHING@ to find a new match. For tickets where one or
-- more players failed to respond, the ticket status is set to @CANCELLED@,
-- and processing is terminated. A new matchmaking request for these
-- players can be submitted as needed.
--
-- __Learn more__
--
-- <https://docs.aws.amazon.com/gamelift/latest/flexmatchguide/match-client.html Add FlexMatch to a game client>
--
-- <https://docs.aws.amazon.com/gamelift/latest/flexmatchguide/match-events.html FlexMatch events>
-- (reference)
--
-- __Related actions__
--
-- StartMatchmaking | DescribeMatchmaking | StopMatchmaking | AcceptMatch |
-- StartMatchBackfill |
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets All APIs by task>
module Amazonka.GameLift.AcceptMatch
  ( -- * Creating a Request
    AcceptMatch (..),
    newAcceptMatch,

    -- * Request Lenses
    acceptMatch_ticketId,
    acceptMatch_playerIds,
    acceptMatch_acceptanceType,

    -- * Destructuring the Response
    AcceptMatchResponse (..),
    newAcceptMatchResponse,

    -- * Response Lenses
    acceptMatchResponse_httpStatus,
  )
where

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

-- | Represents the input for a request operation.
--
-- /See:/ 'newAcceptMatch' smart constructor.
data AcceptMatch = AcceptMatch'
  { -- | A unique identifier for a matchmaking ticket. The ticket must be in
    -- status @REQUIRES_ACCEPTANCE@; otherwise this request will fail.
    AcceptMatch -> Text
ticketId :: Prelude.Text,
    -- | A unique identifier for a player delivering the response. This parameter
    -- can include one or multiple player IDs.
    AcceptMatch -> [Text]
playerIds :: [Prelude.Text],
    -- | Player response to the proposed match.
    AcceptMatch -> AcceptanceType
acceptanceType :: AcceptanceType
  }
  deriving (AcceptMatch -> AcceptMatch -> Bool
(AcceptMatch -> AcceptMatch -> Bool)
-> (AcceptMatch -> AcceptMatch -> Bool) -> Eq AcceptMatch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AcceptMatch -> AcceptMatch -> Bool
$c/= :: AcceptMatch -> AcceptMatch -> Bool
== :: AcceptMatch -> AcceptMatch -> Bool
$c== :: AcceptMatch -> AcceptMatch -> Bool
Prelude.Eq, ReadPrec [AcceptMatch]
ReadPrec AcceptMatch
Int -> ReadS AcceptMatch
ReadS [AcceptMatch]
(Int -> ReadS AcceptMatch)
-> ReadS [AcceptMatch]
-> ReadPrec AcceptMatch
-> ReadPrec [AcceptMatch]
-> Read AcceptMatch
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AcceptMatch]
$creadListPrec :: ReadPrec [AcceptMatch]
readPrec :: ReadPrec AcceptMatch
$creadPrec :: ReadPrec AcceptMatch
readList :: ReadS [AcceptMatch]
$creadList :: ReadS [AcceptMatch]
readsPrec :: Int -> ReadS AcceptMatch
$creadsPrec :: Int -> ReadS AcceptMatch
Prelude.Read, Int -> AcceptMatch -> ShowS
[AcceptMatch] -> ShowS
AcceptMatch -> String
(Int -> AcceptMatch -> ShowS)
-> (AcceptMatch -> String)
-> ([AcceptMatch] -> ShowS)
-> Show AcceptMatch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AcceptMatch] -> ShowS
$cshowList :: [AcceptMatch] -> ShowS
show :: AcceptMatch -> String
$cshow :: AcceptMatch -> String
showsPrec :: Int -> AcceptMatch -> ShowS
$cshowsPrec :: Int -> AcceptMatch -> ShowS
Prelude.Show, (forall x. AcceptMatch -> Rep AcceptMatch x)
-> (forall x. Rep AcceptMatch x -> AcceptMatch)
-> Generic AcceptMatch
forall x. Rep AcceptMatch x -> AcceptMatch
forall x. AcceptMatch -> Rep AcceptMatch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AcceptMatch x -> AcceptMatch
$cfrom :: forall x. AcceptMatch -> Rep AcceptMatch x
Prelude.Generic)

-- |
-- Create a value of 'AcceptMatch' 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:
--
-- 'ticketId', 'acceptMatch_ticketId' - A unique identifier for a matchmaking ticket. The ticket must be in
-- status @REQUIRES_ACCEPTANCE@; otherwise this request will fail.
--
-- 'playerIds', 'acceptMatch_playerIds' - A unique identifier for a player delivering the response. This parameter
-- can include one or multiple player IDs.
--
-- 'acceptanceType', 'acceptMatch_acceptanceType' - Player response to the proposed match.
newAcceptMatch ::
  -- | 'ticketId'
  Prelude.Text ->
  -- | 'acceptanceType'
  AcceptanceType ->
  AcceptMatch
newAcceptMatch :: Text -> AcceptanceType -> AcceptMatch
newAcceptMatch Text
pTicketId_ AcceptanceType
pAcceptanceType_ =
  AcceptMatch' :: Text -> [Text] -> AcceptanceType -> AcceptMatch
AcceptMatch'
    { $sel:ticketId:AcceptMatch' :: Text
ticketId = Text
pTicketId_,
      $sel:playerIds:AcceptMatch' :: [Text]
playerIds = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:acceptanceType:AcceptMatch' :: AcceptanceType
acceptanceType = AcceptanceType
pAcceptanceType_
    }

-- | A unique identifier for a matchmaking ticket. The ticket must be in
-- status @REQUIRES_ACCEPTANCE@; otherwise this request will fail.
acceptMatch_ticketId :: Lens.Lens' AcceptMatch Prelude.Text
acceptMatch_ticketId :: (Text -> f Text) -> AcceptMatch -> f AcceptMatch
acceptMatch_ticketId = (AcceptMatch -> Text)
-> (AcceptMatch -> Text -> AcceptMatch)
-> Lens AcceptMatch AcceptMatch Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AcceptMatch' {Text
ticketId :: Text
$sel:ticketId:AcceptMatch' :: AcceptMatch -> Text
ticketId} -> Text
ticketId) (\s :: AcceptMatch
s@AcceptMatch' {} Text
a -> AcceptMatch
s {$sel:ticketId:AcceptMatch' :: Text
ticketId = Text
a} :: AcceptMatch)

-- | A unique identifier for a player delivering the response. This parameter
-- can include one or multiple player IDs.
acceptMatch_playerIds :: Lens.Lens' AcceptMatch [Prelude.Text]
acceptMatch_playerIds :: ([Text] -> f [Text]) -> AcceptMatch -> f AcceptMatch
acceptMatch_playerIds = (AcceptMatch -> [Text])
-> (AcceptMatch -> [Text] -> AcceptMatch)
-> Lens AcceptMatch AcceptMatch [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AcceptMatch' {[Text]
playerIds :: [Text]
$sel:playerIds:AcceptMatch' :: AcceptMatch -> [Text]
playerIds} -> [Text]
playerIds) (\s :: AcceptMatch
s@AcceptMatch' {} [Text]
a -> AcceptMatch
s {$sel:playerIds:AcceptMatch' :: [Text]
playerIds = [Text]
a} :: AcceptMatch) (([Text] -> f [Text]) -> AcceptMatch -> f AcceptMatch)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> AcceptMatch
-> f AcceptMatch
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Player response to the proposed match.
acceptMatch_acceptanceType :: Lens.Lens' AcceptMatch AcceptanceType
acceptMatch_acceptanceType :: (AcceptanceType -> f AcceptanceType)
-> AcceptMatch -> f AcceptMatch
acceptMatch_acceptanceType = (AcceptMatch -> AcceptanceType)
-> (AcceptMatch -> AcceptanceType -> AcceptMatch)
-> Lens AcceptMatch AcceptMatch AcceptanceType AcceptanceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AcceptMatch' {AcceptanceType
acceptanceType :: AcceptanceType
$sel:acceptanceType:AcceptMatch' :: AcceptMatch -> AcceptanceType
acceptanceType} -> AcceptanceType
acceptanceType) (\s :: AcceptMatch
s@AcceptMatch' {} AcceptanceType
a -> AcceptMatch
s {$sel:acceptanceType:AcceptMatch' :: AcceptanceType
acceptanceType = AcceptanceType
a} :: AcceptMatch)

instance Core.AWSRequest AcceptMatch where
  type AWSResponse AcceptMatch = AcceptMatchResponse
  request :: AcceptMatch -> Request AcceptMatch
request = Service -> AcceptMatch -> Request AcceptMatch
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AcceptMatch
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AcceptMatch)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse AcceptMatch))
-> Logger
-> Service
-> Proxy AcceptMatch
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AcceptMatch)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> AcceptMatchResponse
AcceptMatchResponse'
            (Int -> AcceptMatchResponse)
-> Either String Int -> Either String AcceptMatchResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AcceptMatch

instance Prelude.NFData AcceptMatch

instance Core.ToHeaders AcceptMatch where
  toHeaders :: AcceptMatch -> ResponseHeaders
toHeaders =
    ResponseHeaders -> AcceptMatch -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"GameLift.AcceptMatch" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON AcceptMatch where
  toJSON :: AcceptMatch -> Value
toJSON AcceptMatch' {[Text]
Text
AcceptanceType
acceptanceType :: AcceptanceType
playerIds :: [Text]
ticketId :: Text
$sel:acceptanceType:AcceptMatch' :: AcceptMatch -> AcceptanceType
$sel:playerIds:AcceptMatch' :: AcceptMatch -> [Text]
$sel:ticketId:AcceptMatch' :: AcceptMatch -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TicketId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ticketId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PlayerIds" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
playerIds),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"AcceptanceType" Text -> AcceptanceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AcceptanceType
acceptanceType)
          ]
      )

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

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

-- | /See:/ 'newAcceptMatchResponse' smart constructor.
data AcceptMatchResponse = AcceptMatchResponse'
  { -- | The response's http status code.
    AcceptMatchResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AcceptMatchResponse -> AcceptMatchResponse -> Bool
(AcceptMatchResponse -> AcceptMatchResponse -> Bool)
-> (AcceptMatchResponse -> AcceptMatchResponse -> Bool)
-> Eq AcceptMatchResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AcceptMatchResponse -> AcceptMatchResponse -> Bool
$c/= :: AcceptMatchResponse -> AcceptMatchResponse -> Bool
== :: AcceptMatchResponse -> AcceptMatchResponse -> Bool
$c== :: AcceptMatchResponse -> AcceptMatchResponse -> Bool
Prelude.Eq, ReadPrec [AcceptMatchResponse]
ReadPrec AcceptMatchResponse
Int -> ReadS AcceptMatchResponse
ReadS [AcceptMatchResponse]
(Int -> ReadS AcceptMatchResponse)
-> ReadS [AcceptMatchResponse]
-> ReadPrec AcceptMatchResponse
-> ReadPrec [AcceptMatchResponse]
-> Read AcceptMatchResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AcceptMatchResponse]
$creadListPrec :: ReadPrec [AcceptMatchResponse]
readPrec :: ReadPrec AcceptMatchResponse
$creadPrec :: ReadPrec AcceptMatchResponse
readList :: ReadS [AcceptMatchResponse]
$creadList :: ReadS [AcceptMatchResponse]
readsPrec :: Int -> ReadS AcceptMatchResponse
$creadsPrec :: Int -> ReadS AcceptMatchResponse
Prelude.Read, Int -> AcceptMatchResponse -> ShowS
[AcceptMatchResponse] -> ShowS
AcceptMatchResponse -> String
(Int -> AcceptMatchResponse -> ShowS)
-> (AcceptMatchResponse -> String)
-> ([AcceptMatchResponse] -> ShowS)
-> Show AcceptMatchResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AcceptMatchResponse] -> ShowS
$cshowList :: [AcceptMatchResponse] -> ShowS
show :: AcceptMatchResponse -> String
$cshow :: AcceptMatchResponse -> String
showsPrec :: Int -> AcceptMatchResponse -> ShowS
$cshowsPrec :: Int -> AcceptMatchResponse -> ShowS
Prelude.Show, (forall x. AcceptMatchResponse -> Rep AcceptMatchResponse x)
-> (forall x. Rep AcceptMatchResponse x -> AcceptMatchResponse)
-> Generic AcceptMatchResponse
forall x. Rep AcceptMatchResponse x -> AcceptMatchResponse
forall x. AcceptMatchResponse -> Rep AcceptMatchResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AcceptMatchResponse x -> AcceptMatchResponse
$cfrom :: forall x. AcceptMatchResponse -> Rep AcceptMatchResponse x
Prelude.Generic)

-- |
-- Create a value of 'AcceptMatchResponse' 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:
--
-- 'httpStatus', 'acceptMatchResponse_httpStatus' - The response's http status code.
newAcceptMatchResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AcceptMatchResponse
newAcceptMatchResponse :: Int -> AcceptMatchResponse
newAcceptMatchResponse Int
pHttpStatus_ =
  AcceptMatchResponse' :: Int -> AcceptMatchResponse
AcceptMatchResponse' {$sel:httpStatus:AcceptMatchResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData AcceptMatchResponse