package com.abbidot.tracker.bean

import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import com.abbidot.baselibrary.constant.ConState
import com.abbidot.baselibrary.constant.DeviceType
import com.abbidot.tracker.base.BaseDiffBean
import com.abbidot.tracker.database.MyDatabase
import kotlinx.parcelize.Parcelize

/**
 *Created  by .yzq on 2021/11/8/008.
 * @link
 * @description:连接保存的设备表
 */
// 定义表名称，SQLite 中的表名称不区分大小写,2个主键
@Entity(tableName = MyDatabase.DEVICE_TABLE, primaryKeys = ["deviceOutId", "deviceId"])
@Parcelize
data class DeviceBean(//@PrimaryKey(autoGenerate = true) var id: Long,//autoGenerate = true 自动增长分配ID
    @ColumnInfo @DeviceType var type: Int,//设备类型
    @ColumnInfo var deviceName: String,
    @ColumnInfo var deviceOutId: String,
    @ColumnInfo var deviceId: String,
    @ColumnInfo var shared: Int, //0=没有分享，1=是授权分享的
    @ColumnInfo var batteryCapacity: Int,
    @ColumnInfo var ledSwitch: Int,
    @ColumnInfo @ConState var conState: Int,//连接状态
    @ColumnInfo var macId: String,
    @ColumnInfo var deviceInfoId: String,
    @ColumnInfo var surplusDays: Int,
    @ColumnInfo var gnssSignal: Int,
    @ColumnInfo var lteSignal: Int,
    @ColumnInfo var turnOff: Int,
    @ColumnInfo var lightMode: Int,
    @Ignore var deviceType: Int,
    @Ignore var pet: PetBean?
) : BaseDiffBean(), Parcelable {
    // 如果某个实体中有您不想保留的字段，则可以使用 @Ignore 为这些字段添加注释

    //设置空的构造方法
    constructor() : this(
        DeviceType.TYPE_ONE,
        "",
        "",
        "",
        0,
        0,
        0,
        ConState.DISCONNECTED,
        "",
        "",
        0,
        0,
        0,
        0,
        0,
        1,
        null
    )

    override fun isSameObject(other: Any): Boolean {
        val oldItem = other as DeviceBean
        return deviceId == oldItem.deviceId
    }

    override fun hasSameContent(other: Any): Boolean {
        val oldItem = other as DeviceBean
        return oldItem.deviceOutId == deviceOutId && oldItem.batteryCapacity == batteryCapacity && oldItem.ledSwitch == ledSwitch && oldItem.pet == pet && oldItem.gnssSignal == gnssSignal && oldItem.lteSignal == lteSignal
    }
}