package com.example.iot_controlhost.model;

import java.util.Objects;
import java.util.Random;

/**
 * 定时消毒任务
 */
public class MyTask implements Comparable<MyTask> {
    /**
     * 任务Id 正为开启，负为关闭
     */
    private int id;
    /**
     * 执行设备
     */
    private int deviceType;
    /**
     * 开始时间 小时
     */
    private int startTimeHour;
    /**
     * 开始时间 分钟
     */
    private int startTimeMinute;
    /**
     * 结束时间 小时
     */
    private int endTimeHour;
    /**
     * 结束时间 分钟
     */
    private int endTimeMinute;

    public MyTask() {
    }

    public MyTask(int startTimeHour, int startTimeMinute, int endTimeHour, int endTimeMinute) {
        this.id = new Random(System.currentTimeMillis()).nextInt();
        this.startTimeHour = startTimeHour;
        this.startTimeMinute = startTimeMinute;
        this.endTimeHour = endTimeHour;
        this.endTimeMinute = endTimeMinute;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MyTask other = (MyTask) o;
        return id == other.getId();
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getDeviceType() {
        return deviceType;
    }

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

    public int getStartTimeHour() {
        return startTimeHour;
    }

    public void setStartTimeHour(int startTimeHour) {
        this.startTimeHour = startTimeHour;
    }

    public int getStartTimeMinute() {
        return startTimeMinute;
    }

    public void setStartTimeMinute(int startTimeMinute) {
        this.startTimeMinute = startTimeMinute;
    }

    public int getEndTimeHour() {
        return endTimeHour;
    }

    public void setEndTimeHour(int endTimeHour) {
        this.endTimeHour = endTimeHour;
    }

    public int getEndTimeMinute() {
        return endTimeMinute;
    }

    public void setEndTimeMinute(int endTimeMinute) {
        this.endTimeMinute = endTimeMinute;
    }


    @Override
    public int compareTo(MyTask myTask) {
        if (startTimeHour == myTask.startTimeHour && startTimeMinute == myTask.startTimeMinute) {
            return 0;
        } else if (startTimeHour > myTask.startTimeHour || (startTimeHour == myTask.startTimeHour && startTimeMinute > myTask.startTimeMinute)) {
            return 1;
        } else {
            return -1;
        }
    }
}
