package com.cool.store.dto.huoma;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.cool.store.utils.BrowserVersionUtils;
import com.cool.store.utils.StringUtil;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2025/8/18 16:27
 * @Version 1.0
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class StoreXinFaDeviceDetail {

    /**
     * 设备ID
     */
    @ApiModelProperty(value = "设备ID")
    private String id;

    @ApiModelProperty("设备id")
    private String deviceId;

    /**
     * 设备名称
     */
    @ApiModelProperty(value = "设备名称")
    private String name;

    /**
     * 设备连接状态 0:未连接 1:已连接
     */
    @ApiModelProperty(value = "设备连接状态未连接 1:已连接")
    private Boolean isConnect;

    @ApiModelProperty(value = "授权码")
    private String activateSn;

    /**
     * 设备总内存
     */
    @ApiModelProperty(value = "设备总内存")
    private String totalRam;

    /**
     * 设备可用内存
     */
    @ApiModelProperty(value = "设备可用内存")
    private String availRam;

    /**
     * 设备浏览器信息
     */
    @ApiModelProperty(value = "设备浏览器信息")
    private String userAgent;

    /**
     * 内用内存小于300M 或者 浏览器版本小于60
     */
    @ApiModelProperty(value = "内用内存小于300M 或者 浏览器版本小于60")
    private Boolean flag;

    @ApiModelProperty("应用版本")
    private String appVersion;

    @ApiModelProperty("屏幕角度")
    private String screenAngle;

    @ApiModelProperty("分类ID")
    private Long classifyId;

    @ApiModelProperty("点位名称")
    private String pointName;

    @ApiModelProperty("渠道")
    private Integer channel;

    @ApiModelProperty("类型")
    private Integer type;

    @ApiModelProperty("商户名称")
    private String merchantName;

    @ApiModelProperty("销售人ID")
    private Long sellerId;

    @ApiModelProperty("客户端类型")
    private String clientType;

    @ApiModelProperty("管理信息")
    private String manageInfo;

    @ApiModelProperty("节目名称")
    private String programName;

    @ApiModelProperty("型号")
    private String model;

//    @ApiModelProperty("标签")
//    private List<String> tag;

    @ApiModelProperty("品牌")
    private String brand;

    @ApiModelProperty("屏幕点位")
    private Integer screenPoint;

    @ApiModelProperty("是否子终端")
    private Boolean isChildTerminal;

    @ApiModelProperty("序列号")
    private String serialNum;

    @ApiModelProperty("签到时间")
    private String signTime;

    @ApiModelProperty("IP地址")
    private String ip;

    @ApiModelProperty("CPU")
    private String cpu;

    @ApiModelProperty("是否激活")
    private Boolean active;

    @ApiModelProperty("激活时间")
    private String activateTime;

    @ApiModelProperty("时区")
    private String timeZone;

    @ApiModelProperty("空闲容量")
    private String freeCapacity;

    @ApiModelProperty("设备信息")
    private String deviceInfo;

    @ApiModelProperty("使用状态")
    private Integer useStatus;

    @ApiModelProperty("POS X坐标")
    private Integer posX;

    @ApiModelProperty("POS Y坐标")
    private Integer posY;

    @ApiModelProperty("授权信息")
    private License license;

    @ApiModelProperty("门店容量")
    private String storeCapacity;

    @ApiModelProperty("尺寸")
    private String size;

    @ApiModelProperty("图片模式")
    private String imgMode;

    @ApiModelProperty("设备唯一ID")
    private String deviceUId;

    @ApiModelProperty("设备")
    private String device;

//    @ApiModelProperty("标签ID列表")
//    private List<String> tagIdList;

    @ApiModelProperty("最后更新时间")
    private String lastUpdateTime;

    @ApiModelProperty("日志类型")
    private String logType;

    @ApiModelProperty("编码")
    private String code;

    @ApiModelProperty("是否连接")
    private Boolean connect;

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("终端ID")
    private Long terminalId;

    @ApiModelProperty("视频模式")
    private String videoMode;

    @ApiModelProperty("MAC地址")
    private String mac;

    @ApiModelProperty("制造商")
    private String manufacturer;

    @ApiModelProperty("H5版本")
    private String h5Version;

    @ApiModelProperty("是否删除")
    private Boolean isDeleted;

    @ApiModelProperty("操作系统版本")
    private String osVersion;

    @ApiModelProperty("点位ID")
    private Long pointId;

    @ApiModelProperty("行数")
    private Integer rowCount;

    @ApiModelProperty("DPI")
    private String dpi;

    @ApiModelProperty("渠道ID")
    private Long channelId;

    @ApiModelProperty("方向")
    private String orientation;

    @ApiModelProperty("创建时间")
    private String createTime;

    @ApiModelProperty("操作系统")
    private String os;

    @ApiModelProperty("切换配置")
    private String switchConfig;

    @ApiModelProperty("浏览器内核")
    private String browserKernel;

    @ApiModelProperty("更新时间")
    private String updateTime;

    @ApiModelProperty("点位编号")
    private String pointNo;

    @ApiModelProperty("Token")
    private String token;

    @ApiModelProperty("删除")
    private Boolean deleted;

    @ApiModelProperty("列数")
    private Integer colCount;

    @ApiModelProperty("链接类型")
    private String linkType;

    @ApiModelProperty("渠道名称")
    private String channelName;

    @ApiModelProperty("操作")
    private List<String> operation;

    @ApiModelProperty("节目ID")
    private Long programId;

    public boolean getFlag() {
        if (StringUtil.isEmpty(availRam)||StringUtil.isEmpty(userAgent)){
            return false;
        }
        try {
            Boolean isOldChromeBrowser = BrowserVersionUtils.isOldChromeBrowser(userAgent);
            long availableMemoryMB = Long.parseLong(availRam) / (1024 * 1024);
            return availableMemoryMB < 300 || isOldChromeBrowser;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    public String getName(){
        return name+"  授权码："+activateSn;
    }

    public String getDeviceId() {
        return id;
    }

    /**
     * 授权信息内部类
     */
    @Data
    public static class License {
        @ApiModelProperty("开始时间")
        private String startTime;

        @ApiModelProperty("结束时间")
        private String endTime;

        @ApiModelProperty("授权ID")
        private Long id;

        @ApiModelProperty("状态")
        private Integer status;
    }
}
