package cn.lihongjie.coal.emDevice.entity;

import cn.lihongjie.coal.base.entity.OrgCommonEntity;
import cn.lihongjie.coal.emDeviceSupplier.entity.EmDeviceSupplierEntity;
import cn.lihongjie.coal.thirdAccount.entity.ThirdAccountEntity;

import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;

import lombok.Data;

import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;

import java.util.List;

@Data
@Entity
public class EmDeviceEntity extends OrgCommonEntity {

    @ManyToOne EmDeviceSupplierEntity supplier;

    @ManyToOne ThirdAccountEntity thirdAccount;

    @Comment("设备类型")
    private String deviceType;

    @Formula(
            "(select i.name\n"
                    + "from t_dictionary d,\n"
                    + "     t_dictionary_item i\n"
                    + "where d.id = i.dictionary_id\n"
                    + "  and d.code = 'em.device.type'\n"
                    + "  and i.code = device_type)")
    private String deviceTypeName;

    private String location;

    @Comment("归档状态")
    @ColumnDefault("'0'")
    private String archiveStatus = "0";

    @Formula(
            "(select i.name\n"
                    + "from t_dictionary d,\n"
                    + "     t_dictionary_item i\n"
                    + "where d.id = i.dictionary_id\n"
                    + "  and d.code = 'archiveStatus'\n"
                    + "  and i.code = archive_status)")
    private String archiveStatusName;


    @ElementCollection
    private List<EmDeviceItemConfig> itemConfig;


    @Comment("采集间隔(分钟)")
    private Integer interval;
}
