module TD.Query.SetGameScore
  (SetGameScore(..)
  , defaultSetGameScore
  ) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I

-- | Updates the game score of the specified user in the game; for bots only. Returns 'TD.Data.Message.Message'
data SetGameScore
  = SetGameScore
    { SetGameScore -> Maybe Int
chat_id      :: Maybe Int  -- ^ The chat to which the message with the game belongs
    , SetGameScore -> Maybe Int
message_id   :: Maybe Int  -- ^ Identifier of the message
    , SetGameScore -> Maybe Bool
edit_message :: Maybe Bool -- ^ Pass true to edit the game message to include the current scoreboard
    , SetGameScore -> Maybe Int
user_id      :: Maybe Int  -- ^ User identifier
    , SetGameScore -> Maybe Int
score        :: Maybe Int  -- ^ The new score
    , SetGameScore -> Maybe Bool
force        :: Maybe Bool -- ^ Pass true to update the score even if it decreases. If the score is 0, the user will be deleted from the high score table
    }
  deriving (SetGameScore -> SetGameScore -> Bool
(SetGameScore -> SetGameScore -> Bool)
-> (SetGameScore -> SetGameScore -> Bool) -> Eq SetGameScore
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SetGameScore -> SetGameScore -> Bool
== :: SetGameScore -> SetGameScore -> Bool
$c/= :: SetGameScore -> SetGameScore -> Bool
/= :: SetGameScore -> SetGameScore -> Bool
Eq, Int -> SetGameScore -> ShowS
[SetGameScore] -> ShowS
SetGameScore -> String
(Int -> SetGameScore -> ShowS)
-> (SetGameScore -> String)
-> ([SetGameScore] -> ShowS)
-> Show SetGameScore
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetGameScore -> ShowS
showsPrec :: Int -> SetGameScore -> ShowS
$cshow :: SetGameScore -> String
show :: SetGameScore -> String
$cshowList :: [SetGameScore] -> ShowS
showList :: [SetGameScore] -> ShowS
Show)

instance I.ShortShow SetGameScore where
  shortShow :: SetGameScore -> String
shortShow
    SetGameScore
      { chat_id :: SetGameScore -> Maybe Int
chat_id      = Maybe Int
chat_id_
      , message_id :: SetGameScore -> Maybe Int
message_id   = Maybe Int
message_id_
      , edit_message :: SetGameScore -> Maybe Bool
edit_message = Maybe Bool
edit_message_
      , user_id :: SetGameScore -> Maybe Int
user_id      = Maybe Int
user_id_
      , score :: SetGameScore -> Maybe Int
score        = Maybe Int
score_
      , force :: SetGameScore -> Maybe Bool
force        = Maybe Bool
force_
      }
        = String
"SetGameScore"
          String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
          [ String
"chat_id"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
chat_id_
          , String
"message_id"   String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
          , String
"edit_message" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
edit_message_
          , String
"user_id"      String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
          , String
"score"        String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
score_
          , String
"force"        String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
force_
          ]

instance AT.ToJSON SetGameScore where
  toJSON :: SetGameScore -> Value
toJSON
    SetGameScore
      { chat_id :: SetGameScore -> Maybe Int
chat_id      = Maybe Int
chat_id_
      , message_id :: SetGameScore -> Maybe Int
message_id   = Maybe Int
message_id_
      , edit_message :: SetGameScore -> Maybe Bool
edit_message = Maybe Bool
edit_message_
      , user_id :: SetGameScore -> Maybe Int
user_id      = Maybe Int
user_id_
      , score :: SetGameScore -> Maybe Int
score        = Maybe Int
score_
      , force :: SetGameScore -> Maybe Bool
force        = Maybe Bool
force_
      }
        = [Pair] -> Value
A.object
          [ Key
"@type"        Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"setGameScore"
          , Key
"chat_id"      Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
chat_id_
          , Key
"message_id"   Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
message_id_
          , Key
"edit_message" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
edit_message_
          , Key
"user_id"      Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
user_id_
          , Key
"score"        Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
score_
          , Key
"force"        Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
force_
          ]

defaultSetGameScore :: SetGameScore
defaultSetGameScore :: SetGameScore
defaultSetGameScore =
  SetGameScore
    { chat_id :: Maybe Int
chat_id      = Maybe Int
forall a. Maybe a
Nothing
    , message_id :: Maybe Int
message_id   = Maybe Int
forall a. Maybe a
Nothing
    , edit_message :: Maybe Bool
edit_message = Maybe Bool
forall a. Maybe a
Nothing
    , user_id :: Maybe Int
user_id      = Maybe Int
forall a. Maybe a
Nothing
    , score :: Maybe Int
score        = Maybe Int
forall a. Maybe a
Nothing
    , force :: Maybe Bool
force        = Maybe Bool
forall a. Maybe a
Nothing
    }