package cn.org.bjca.trust.push.message.msg

import cn.org.bjca.trust.push.enums.PacketType


open class BaseMessage protected constructor(packetType: PacketType) {
    private val packetType: PacketType

    init {
        this.packetType = packetType
    }

    fun getPacketType(): PacketType {
        return packetType
    }

    open fun getClassz(): Class<*> {
        return getClassz(packetType)
    }

    open fun getClassz(packetType: PacketType): Class<*> {
        return when (packetType) {
            PacketType.CONNECT -> ConnectMessage::class.java
            PacketType.CONNACK -> ConnAckMessage::class.java
            PacketType.SEND -> SendMessage::class.java
            PacketType.SENDACK -> AckSendMessage::class.java
            PacketType.PING -> PingMessage::class.java
            PacketType.PANG -> PangMessage::class.java
            PacketType.DISCONNECT -> DisconnectMessage::class.java
            else -> throw IllegalStateException("协议类型不正确！")
        }
    }
}