package main import ( "time" "github.com/google/uuid" ) type QuestionType string const ( QTypeQuiz QuestionType = "quiz" QTypeTrueFalse QuestionType = "true_false" QTypeTypeAnswer QuestionType = "type_answer" QTypePuzzle QuestionType = "puzzle" QTypeSlider QuestionType = "slider" ) type GameState string const ( StateWaiting GameState = "waiting" StateLobby GameState = "lobby" StateQuestion GameState = "question" StateAnswer GameState = "answer" StateLeaderboard GameState = "leaderboard" StateFinished GameState = "finished" ) type User struct { ID string `json:"id"` Username string `json:"username"` Email string `json:"email"` Password string `json:"-"` AvatarURL string `json:"avatar_url"` CreatedAt time.Time `json:"created_at"` } type Quiz struct { ID string `json:"id"` Title string `json:"title"` Description string `json:"description"` CoverImage string `json:"cover_image"` CreatorID string `json:"creator_id"` IsPublic bool `json:"is_public"` Questions []Question `json:"questions"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` PlayCount int `json:"play_count"` } type Question struct { ID string `json:"id"` Type QuestionType `json:"type"` Text string `json:"text"` Image string `json:"image"` TimeLimit int `json:"time_limit"` Points int `json:"points"` Options []Option `json:"options"` CorrectAnswer interface{} `json:"correct_answer"` // Slider specific (stored in options[0].text, options[1].text, options[2].text) } type Option struct { ID string `json:"id"` Text string `json:"text"` Image string `json:"image"` IsCorrect bool `json:"is_correct,omitempty"` } type GameSettings struct { MaxPlayers int `json:"max_players"` RandomizeOrder bool `json:"randomize_order"` ShowAnswers bool `json:"show_answers"` } type Player struct { ID string `json:"id"` Name string `json:"name"` Avatar string `json:"avatar"` Score int `json:"score"` Streak int `json:"streak"` Answer *PlayerAnswer `json:"-"` Connected bool `json:"connected"` // Pour Player dans GameSession IsHost bool `json:"is_host"` } type PlayerAnswer struct { QuestionIndex int `json:"q_index"` Answer interface{} `json:"answer"` TimeTaken int `json:"time_taken"` PointsEarned int `json:"points_earned"` IsCorrect bool `json:"is_correct"` } type GameSession struct { Pin string `json:"pin"` QuizID string `json:"quiz_id"` HostID string `json:"host_id"` State GameState `json:"state"` Players map[string]*Player `json:"players"` CurrentQIndex int `json:"current_q_index"` QuestionStartTime time.Time `json:"-"` Settings GameSettings `json:"settings"` CreatedAt time.Time `json:"created_at"` Quiz *Quiz `json:"-"` // Populé au runtime, pas sauvé en DB } func GeneratePin() string { return uuid.New().String()[:6] } // WS Messages type WSMessage struct { Type string `json:"type"` Data interface{} `json:"data"` } const ( MsgJoin = "join" MsgAnswer = "answer" MsgStartGame = "start_game" MsgNextQuestion = "next_question" MsgLeave = "leave" MsgStateSync = "state_sync" MsgPlayerJoined = "player_joined" MsgPlayerLeft = "player_left" MsgLobbyUpdate = "lobby_update" MsgQuestionStart = "question_start" MsgTimeUpdate = "time_update" MsgAnswerResult = "answer_result" MsgLeaderboard = "leaderboard" MsgGameEnd = "game_end" MsgError = "error" MsgQueueStatus = "queue_status" )