package com.haha.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@TableName("t_device")
public class Device implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    private String deviceId;

    /**
     * 关联的ERP店铺ID（ERP内部shopId）
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long erpShopId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long shopId;

    private String name;

    private String authToken;

    private Integer status;

    private String currentInventoryHash;

    /**
     * 门状态：ERROR-开门失败，OPENED-门已开，CLOSED-门已关，ANOTHER-设备繁忙
     */
    private String doorStatus;

    /**
     * 设备地址（同步自哈哈平台）
     */
    private String address;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime updateTime;

    // ========== 以下为非数据库字段，用于前端展示 ==========

    @TableField(exist = false)
    private String shopName;


    @TableField(exist = false)
    private String deviceTypeLabel;

    @TableField(exist = false)
    private String statusLabel;

    @TableField(exist = false)
    private String statusColor;

    @TableField(exist = false)
    private Boolean isOnline;

    @TableField(exist = false)
    private String temperature;

    @TableField(exist = false)
    private Integer volume;

    @TableField(exist = false)
    private Integer doorCount;

    @TableField(exist = false)
    private Integer layerCount;

    @TableField(exist = false)
    private Boolean hasScreen;

    @TableField(exist = false)
    private String totalSales;

    @TableField(exist = false)
    private String todaySales;

    @TableField(exist = false)
    private Integer orderCount;

    @TableField(exist = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime lastOnlineTime;
}
