package de.kif.common

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.SerializersModule

@Serializable
data class Message(
    val type: MessageType,
    val repository: RepositoryType,
    val id: Long
) {

    fun stringify(): String {
        return json.stringify(serializer(), this)
    }

    companion object {
        private val jsonContext = SerializersModule {}

        val json = Json(context = jsonContext)

        fun parse(data: String): Message {
            return json.parse(serializer(), data)
        }
    }
}

enum class MessageType {
    CREATE, UPDATE, DELETE
}

enum class RepositoryType {
    ROOM, SCHEDULE, TRACK, USER, WORK_GROUP, POST
}
