package com.zsc.edu.gateway.modules.iot.device.entity;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zsc.edu.gateway.common.enums.IState;
import com.zsc.edu.gateway.framework.json.JsonbTypeHandler;
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;
import java.util.Map;

/**
 * @author 15864
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@TableName("iot_device")
public class Device extends BaseEntity {

    /**
     * 设备名称
     */
    private String name;

    /**
     * 设备是否在线，默认在线
     */
    private Boolean online = false;

    /**
     * 设备状态
     */
    private Status state = Status.UNACTIVATED;

    /**
     * 硬件版本
     */
    private String hardwareVersion;

    /**
     * 固件版本
     */
    private String firmwareVersion;


    /**
     * 出厂ID
     */
    private String factoryId;


    /**
     * 客户ID
     */
    private String clientId;

    /**
     * 扩展配置
     */
    @TableField(typeHandler = JsonbTypeHandler.class)
    private List<Map<String, Object>> extendParams;

    /**
     * 设备属性
     */
    @TableField(typeHandler = JsonbTypeHandler.class)
    private List<Map<String, Object>> properties;

    /**
     * 所属产品ID
     */
    public Long productId;

    /**
     * 部门ID(权限)
     */
    public Long deptId;

    /**
     * 所属产品
     */
    @TableField(exist = false)
    public Product product;

    public enum Status implements IEnum<Integer>, IState<Status> {
        UNACTIVATED(0, "未激活"),
        LOCKED(1, "已锁定"),
        ACTIVATED(2, "已激活"),
        DISCARDED(3, "已报废");

        private final int value;
        private final String description;

        Status(int value, String description) {
            this.value = value;
            this.description = description;
        }

        @Override
        public Integer getValue() {
            return this.value;
        }

        @Override
        public String toString() {
            return this.description;
        }
    }
}

