package org.DUCodeWars.framework.server.net.packets.notifications.packets

import com.google.gson.JsonObject
import org.DUCodeWars.framework.server.net.packets.JsonSerialiser
import org.DUCodeWars.framework.server.net.packets.notifications.NotificationPacketSer
import org.DUCodeWars.framework.server.net.packets.notifications.NotificationRequest

private val action = "id"

class IdPS : NotificationPacketSer<IdRequest>(action) {
    override val reqSer = IdReqSer()
}

class IdRequest(val id: Int) : NotificationRequest(action) {
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        if (!super.equals(other)) return false

        other as IdRequest

        if (id != other.id) return false

        return true
    }

    override fun hashCode(): Int {
        var result = super.hashCode()
        result = 31 * result + id
        return result
    }
}

class IdReqSer() : JsonSerialiser<IdRequest>() {
    override fun ser(packet: IdRequest): JsonObject {
        val json = JsonObject()
        json.addProperty("id", packet.id)
        return json
    }

    override fun deserialise(json: JsonObject): IdRequest {
        val id = json["id"].asInt
        return IdRequest(id)
    }
}