package com.xlzn.hcpda.uhf.entity

import android.annotation.SuppressLint
import kotlinx.serialization.Serializable
import java.math.BigInteger
import java.util.Objects

/**
 *
 * UHF 标签实体类
 */
@SuppressLint("UnsafeOptInUsageError")
@Serializable
class UHFTagEntity : Comparable<UHFTagEntity> {
    /**
     * 获取标签TID数据
     * @return 十六字节TID数据
     */
    //public class UHFTagEntity  {
    @JvmField
    var tidHex: String? = null
    private var ecpHex: String? = null

    /**
     * 获取PC数据
     * @return 十六字节PC数据
     */
    @JvmField
    var pcHex: String? = null
    var userHex: String? = null

    /**
     * 获取RSSI数据
     * @return RSSI数据
     */
    @JvmField
    var rssi: Int = 0

    /**
     * 获取ANT数据
     * @return ANT数据
     */
    @JvmField
    var ant: Int = 0

    /**
     * 获取标签次数数据
     * @return 标签次数数据
     */
    @JvmField
    var count: Int = 0


    /**
     * 获取EPC数据
     * @return 十六字节EPC数据
     */
    fun getEcpHex(): String {
        return ecpHex!!
    }

    fun setEcpHex(ecpHex: String) {
        this.ecpHex = ecpHex
    }

    override fun equals(o: Any?): Boolean {
        if (this === o) return true
        if (o !is UHFTagEntity) return false
        val person = o
        return ecpHex == person.ecpHex
    }


    override fun hashCode(): Int {
        return Objects.hash(ecpHex)
    }

    override fun compareTo(o: UHFTagEntity): Int {
        val ecpHex = getEcpHex()
        val ecpHex2 = o.getEcpHex()
        val one = BigInteger(ecpHex, 16)
        val two = BigInteger(ecpHex2, 16)

        //        one.compareTo(two);
        return one.compareTo(two)
    }
}
