package easydo.technology.core;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.alibaba.fastjson.annotation.JSONField;

import zmo.technology.lite.core.ZeroCoreStructs;

public class EasydoCoreDevice {

    public static class EasydoDevice extends ZeroCoreStructs {

        private String deviceIdentifier;
        private String deviceType;
        private List<EasydoSensor> sensors;

        private List<EasydoDeviceHealth> healths;

        public EasydoDevice() {
            super();
        }

        public EasydoDevice(ResultSet set) throws SQLException {
            super(set);

            if (inResultSet(set, "DEVICE_IDENTIFIER"))
                deviceIdentifier = set.getString("DEVICE_IDENTIFIER");

            if (inResultSet(set, "DEVICE_TYPE"))
                deviceType = set.getString("DEVICE_TYPE");
        }

        public String getDeviceIdentifier() {
            return deviceIdentifier;
        }

        public void setDeviceIdentifier(String deviceIdentifier) {
            this.deviceIdentifier = deviceIdentifier;
        }

        public String getDeviceType() {
            return deviceType;
        }

        public void setDeviceType(String deviceType) {
            this.deviceType = deviceType;
        }

        public List<EasydoSensor> getSensors() {
            return sensors;
        }

        public void setSensors(List<EasydoSensor> sensors) {
            this.sensors = sensors;
        }

        public List<EasydoDeviceHealth> getHealths() {
            return healths;
        }

        public void setHealths(List<EasydoDeviceHealth> healths) {
            this.healths = healths;
        }
    }

    public static class EasydoDeviceHealth extends ZeroCoreStructs {

        private EasydoDevice device;

        public EasydoDeviceHealth() {
            super();
        }

        public EasydoDeviceHealth(ResultSet set) throws SQLException {
            super(set);

            if (inResultSet(set, "DEVICE_ID")) {
                device = new EasydoDevice();
                device.setId(UUID.fromString(set.getString("DEVICE_ID")));
            }
        }

        public EasydoDevice getDevice() {
            return device;
        }

        public void setDevice(EasydoDevice device) {
            this.device = device;
        }
    }

    public static class EasydoSensor extends ZeroCoreStructs {

        private EasydoDevice device;
        private String sensorIdentifier;
        private String sensorType;

        public EasydoSensor() {
            super();
        }

        public EasydoSensor(ResultSet set) throws SQLException {
            super(set);

            if (inResultSet(set, "DEVICE_ID")) {
                device = new EasydoDevice();
                device.setId(UUID.fromString(set.getString("DEVICE_ID")));
            }

            if (inResultSet(set, "SENSOR_IDENTIFIER"))
                sensorIdentifier = set.getString("SENSOR_IDENTIFIER");

            if (inResultSet(set, "SENSOR_TYPE"))
                sensorType = set.getString("SENSOR_TYPE");
        }

        public EasydoDevice getDevice() {
            return device;
        }

        public void setDevice(EasydoDevice device) {
            this.device = device;
        }

        public String getSensorIdentifier() {
            return sensorIdentifier;
        }

        public void setSensorIdentifier(String sensorIdentifier) {
            this.sensorIdentifier = sensorIdentifier;
        }

        public String getSensorType() {
            return sensorType;
        }

        public void setSensorType(String sensorType) {
            this.sensorType = sensorType;
        }

    }

    public static class EasydoSensorRecord extends ZeroCoreStructs {

        private EasydoSensor sensor;

        @JSONField(format = CURACAO_DATE_FORMAT)
        protected Date reportTime;

        public EasydoSensorRecord() {
            super();
        }

        public EasydoSensorRecord(ResultSet set) throws SQLException {
            super(set);

            if (inResultSet(set, "SENSOR_ID")) {
                sensor = new EasydoSensor();
                sensor.setId(UUID.fromString(set.getString("SENSOR_ID")));
            }

            if (inResultSet(set, "REPORT_TIME"))
                reportTime = new Date(set.getTimestamp("REPORT_TIME").getTime());
        }

        public Date getReportTime() {
            return reportTime;
        }

        public void setReportTime(Date reportTime) {
            this.reportTime = reportTime;
        }

        public EasydoSensor getSensor() {
            return sensor;
        }

        public void setSensor(EasydoSensor sensor) {
            this.sensor = sensor;
        }
    }

}
