package easydo.technology.core;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

import com.alibaba.fastjson.annotation.JSONField;

import lombok.Getter;
import lombok.Setter;
import zmo.technology.lite.core.ZeroCoreStructs;

@Setter
@Getter
public class DeviceStock {

    private long id;
    private long category_id;
    private long model_id;
    private long msg_id;
    private String device_num;
    private long project_id;
    private int device_status;
    private int del_log;
    private String remark;
    private String device_pic;
    private long spec_model_id;
    private String sdplatform;

    @JSONField(format = ZeroCoreStructs.CURACAO_DATE_FORMAT)
    private Date healthbeatTime;

    public DeviceStock() {
        super();
    }

    public DeviceStock(ResultSet set) throws SQLException {
        super();
        if (ZeroCoreStructs.inResultSet(set, "ID"))
            id = set.getLong("ID");

        if (ZeroCoreStructs.inResultSet(set, "CATEGORY_ID"))
            category_id = set.getLong("CATEGORY_ID");

        if (ZeroCoreStructs.inResultSet(set, "MODEL_ID"))
            model_id = set.getLong("MODEL_ID");

        if (ZeroCoreStructs.inResultSet(set, "MSG_ID"))
            msg_id = set.getLong("MSG_ID");

        if (ZeroCoreStructs.inResultSet(set, "DEVICE_NUM"))
            device_num = set.getString("DEVICE_NUM");

        if (ZeroCoreStructs.inResultSet(set, "PROJECT_ID"))
            project_id = set.getLong("PROJECT_ID");

        if (ZeroCoreStructs.inResultSet(set, "DEVICE_STATUS"))
            device_status = set.getInt("DEVICE_STATUS");

        if (ZeroCoreStructs.inResultSet(set, "DEL_LOG"))
            del_log = set.getInt("DEL_LOG");

        if (ZeroCoreStructs.inResultSet(set, "REMARK"))
            remark = set.getString("REMARK");

        if (ZeroCoreStructs.inResultSet(set, "DEVICE_PIC"))
            device_pic = set.getString("DEVICE_PIC");

        if (ZeroCoreStructs.inResultSet(set, "SPEC_MODEL_ID"))
            spec_model_id = set.getLong("SPEC_MODEL_ID");

        if (ZeroCoreStructs.inResultSet(set, "HEALTHBEAT_TIME")) {
            Timestamp timestamp = set.getTimestamp("HEALTHBEAT_TIME");
            if (timestamp != null)
                healthbeatTime = new Date(timestamp.getTime());
        }
    }
}