package fr.teamflash.fencerjudgeback.websocket.models

import fr.teamflash.fencerjudgeback.entities.PlayerBean

/**
 * Message model for player updates sent through WebSocket
 */
data class PlayerUpdateMessage(
    val playerId: Long,
    val name: String?,
    val firstName: String?,
    val club: String?,
    val type: UpdateType = UpdateType.PLAYER_UPDATE
) {
    enum class UpdateType {
        PLAYER_UPDATE,
        PLAYER_CREATE,
        PLAYER_DELETE
    }

    companion object {
        /**
         * Create a PlayerUpdateMessage from a PlayerBean
         */
        fun fromPlayerBean(playerBean: PlayerBean, type: UpdateType = UpdateType.PLAYER_UPDATE): PlayerUpdateMessage {
            return PlayerUpdateMessage(
                playerId = playerBean.id ?: 0,
                name = playerBean.name,
                firstName = playerBean.firstName,
                club = playerBean.club,
                type = type
            )
        }
    }
}
