package fr.teamflash.fencerjudgeback.websocket.models

import fr.teamflash.fencerjudgeback.entities.MatchBean
import java.util.*

/**
 * Message model for match updates sent through WebSocket
 */
data class MatchUpdateMessage(
    val matchId: Long,
    val player1Id: Long?,
    val player2Id: Long?,
    val refereeId: Long?,
    val score1: Int,
    val score2: Int,
    val date: Date?,
    val type: UpdateType = UpdateType.SCORE_UPDATE
) {
    enum class UpdateType {
        SCORE_UPDATE,
        MATCH_START,
        MATCH_END,
        MATCH_CANCEL,
        NEW_MATCH,
    }
    
    companion object {
        /**
         * Create a MatchUpdateMessage from a MatchBean
         */
        fun fromMatchBean(matchBean: MatchBean, type: UpdateType = UpdateType.SCORE_UPDATE): MatchUpdateMessage {
            return MatchUpdateMessage(
                matchId = matchBean.id ?: 0,
                player1Id = matchBean.player1ID,
                player2Id = matchBean.player2ID,
                refereeId = matchBean.refereeID,
                score1 = matchBean.score1,
                score2 = matchBean.score2,
                date = matchBean.date,
                type = type
            )
        }
    }
}