package com.gyee.wisdom.dao.sql.things.entity;

import com.gyee.wisdom.common.data.ToData;
import com.gyee.wisdom.common.data.system.model.User;
import com.gyee.wisdom.common.data.timeseries.BasicTsPoint;
import com.gyee.wisdom.common.data.timeseries.TsDataType;
import com.gyee.wisdom.common.data.timeseries.TsPoint;
import com.gyee.wisdom.dao.sql.ModelConstants;
import com.gyee.wisdom.dao.sql.system.entity.RoleEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Data
@NoArgsConstructor
@ToString
@EqualsAndHashCode()
@Entity
@Table(name = "view_tspoint")
@Cacheable
public class TsPointEntity implements ToData<TsPoint> {
    /**
     * 主键ID
     */
    @Id
    //@GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private String id;
    /**
     * 设备类型
     */
    @Column(name = ModelConstants.THING_TYPE)
    private String thingType;
    /**
     * 设备Id
     */
    @Column(name = ModelConstants.THING_ID)
    private String thingId;
    /**
     * 统一编码
     */
    @Column(name = ModelConstants.UNIFORM_CODE)
    private String uniformCode;
    /**
     * 点类型
     */
    @Column(name = ModelConstants.DATA_TYPE)
    private String dataType;

    /**
     * 附加
     */
    @Column(name = "tag")
    private String tag;

    @Override
    public TsPoint toData() {
        TsDataType tsDataType = TsDataType.DOUBLE;
        if ("bool".equals(this.dataType))
            tsDataType = TsDataType.BOOLEAN;
        else if (this.dataType == null)
            tsDataType = TsDataType.DOUBLE;
        else if (this.dataType.contains("INT"))
            tsDataType = TsDataType.LONG;

        BasicTsPoint data = new BasicTsPoint(this.id, tsDataType);
        if (!"".equals(thingId))
            data.setThingId(this.thingId);
        if (!"".equals(thingType))
            data.setThingType(this.thingType);
        if (!"".equals(uniformCode))
            data.setUniformCode(this.uniformCode);
        if (!"".equals(tag))
            data.setTag(this.tag);
        return data;
    }
}
