package com.bocloud.nms.model.hillstone;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.Objects;

// 时间表
public class TimeBookModel extends HillStoneGenericModel {
    private Long vendorId; // 所属平台
    private String name; // 名称
    private Integer valid; // 活跃状态
    /**
     * start; // 是否设定了起始时间
     * startYear; // 起始年份
     * startMonth; // 起始月份
     * startDay; // 起始日
     * startHour; // 起始时
     * startMinute; // 起始分
     * end; // 是否设定了结束时间
     * endYear; // 结束年份
     * endMonth; // 结束月份
     * endDay; // 结束日
     * endHour; // 结束时
     * endMinute; //  结束分
     */
    private String absolute; // 绝对计划
    /**
     * startHour; // 起始时
     * startMinute; // 起始分
     * endHour; // 结束时
     * endMinute; //  结束分
     */
    private String everyDays; // 周期计划--每天
    /**
     * monday; // 周一
     * tuesday; // 周二
     * wednesday; // 周三
     * thursday; // 周四
     * friday; // 周五
     * saturday; // 周六
     * sunday; // 周日
     * startHour; // 起始时
     * startMinute; // 起始分
     * endHour; // 结束时
     * endMinute; //  结束分
     */
    private String someWeeks; // 周期计划--每周的某几天
    /**
     * startWeek; // 起始周几
     * startHour; // 起始时
     * startMinute; // 起始分
     * endWeek; // 结束周几
     * endHour; // 结束时
     * endMinute; //  结束分
     */
    private String someTimes; // 周期计划--每周的一段时间

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getValid() {
        return valid;
    }

    public void setValid(Integer valid) {
        this.valid = valid;
    }

    public String getAbsolute() {
        return absolute;
    }

    public void setAbsolute(String absolute) {
        this.absolute = absolute;
    }

    public String getEveryDays() {
        return everyDays;
    }

    public void setEveryDays(String everyDays) {
        this.everyDays = everyDays;
    }

    public String getSomeWeeks() {
        return someWeeks;
    }

    public void setSomeWeeks(String someWeeks) {
        this.someWeeks = someWeeks;
    }

    public String getSomeTimes() {
        return someTimes;
    }

    public void setSomeTimes(String someTimes) {
        this.someTimes = someTimes;
    }

    public Long getVendorId() {
        return vendorId;
    }

    public void setVendorId(Long vendorId) {
        this.vendorId = vendorId;
    }

    public String getSomeWeeksString() {
        String someWeeks = this.getSomeWeeks();
        if (someWeeks == null) {
            return null;
        }
        StringBuilder stringBuilder = new StringBuilder();
        JSONObject jsonObject = JSONObject.parseObject(JSONArray.parseArray(someWeeks).get(0).toString());
        stringBuilder.append("每周");
        if (jsonObject.getBoolean("monday")) {
            stringBuilder.append("一、");
        }
        if (jsonObject.getBoolean("tuesday")) {
            stringBuilder.append("二、");
        }
        if (jsonObject.getBoolean("wednesday")) {
            stringBuilder.append("三、");
        }
        if (jsonObject.getBoolean("thursday")) {
            stringBuilder.append("四、");
        }
        if (jsonObject.getBoolean("friday")) {
            stringBuilder.append("五、");
        }
        if (jsonObject.getBoolean("saturday")) {
            stringBuilder.append("六、");
        }
        if (jsonObject.getBoolean("sunday")) {
            stringBuilder.append("日 ");
        }
        stringBuilder.append("的");
        stringBuilder.append(jsonObject.getString("startHour"));
        stringBuilder.append(":");
        stringBuilder.append(jsonObject.getString("startMinute"));
        stringBuilder.append(" 至 ");
        stringBuilder.append(jsonObject.getString("endHour"));
        stringBuilder.append(":");
        stringBuilder.append(jsonObject.getString("endMinute"));
        return stringBuilder.toString();
    }

    public String getEveryDaysString() {
        String everyDays = this.getEveryDays();
        if (everyDays == null) {
            return null;
        }
        StringBuilder stringBuilder = new StringBuilder();
        JSONObject jsonObject = JSONObject.parseObject(JSONArray.parseArray(everyDays).get(0).toString());
        stringBuilder.append("每天");
        stringBuilder.append(jsonObject.getString("startHour"));
        stringBuilder.append(":");
        stringBuilder.append(jsonObject.getString("startMinute"));
        stringBuilder.append(" 至 ");
        stringBuilder.append(jsonObject.getString("endHour"));
        stringBuilder.append(":");
        stringBuilder.append(jsonObject.getString("endMinute"));
        return stringBuilder.toString();
    }

    public String getSomeTimesString() {
        String someTimes = this.getSomeTimes();
        if (null == someTimes) {
            return null;
        }
        StringBuilder stringBuilder = new StringBuilder();
        JSONObject jsonObject = JSONObject.parseObject(JSONArray.parseArray(someTimes).get(0).toString());
        stringBuilder.append("每周");
        stringBuilder.append(jsonObject.getString("startWeek"));
        stringBuilder.append(" 至 周");
        stringBuilder.append(jsonObject.getString("endWeek"));
        stringBuilder.append("的");
        stringBuilder.append(jsonObject.getString("startHour"));
        stringBuilder.append(":");
        stringBuilder.append(jsonObject.getString("startMinute"));
        stringBuilder.append(" 至 ");
        stringBuilder.append(jsonObject.getString("endHour"));
        stringBuilder.append(":");
        stringBuilder.append(jsonObject.getString("endMinute"));
        return stringBuilder.toString();
    }

    public String getAbsoluteString() {
        String absolute = this.getAbsolute();
        if (absolute == null) {
            return null;
        }
        StringBuilder stringBuilder = new StringBuilder();
        JSONObject jsonObject = JSONObject.parseObject(absolute);
        if (1 == jsonObject.getInteger("start")) {
            stringBuilder.append(jsonObject.getString("startYear"));
            stringBuilder.append("-");
            stringBuilder.append(jsonObject.getString("startMonth"));
            stringBuilder.append("-");
            stringBuilder.append(jsonObject.getString("startDay"));
            stringBuilder.append(" ");
            stringBuilder.append(jsonObject.getString("startHour"));
            stringBuilder.append(":");
            stringBuilder.append(jsonObject.getString("startMinute"));
        }
        if (1 == jsonObject.getInteger("end")) {
            stringBuilder.append(" 至 ");
            stringBuilder.append(jsonObject.getString("endYear"));
            stringBuilder.append("-");
            stringBuilder.append(jsonObject.getString("endMonth"));
            stringBuilder.append("-");
            stringBuilder.append(jsonObject.getString("endDay"));
            stringBuilder.append(" ");
            stringBuilder.append(jsonObject.getString("endHour"));
            stringBuilder.append(":");
            stringBuilder.append(jsonObject.getString("endMinute"));
        }
        return stringBuilder.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TimeBookModel timeBook = (TimeBookModel) o;
        return Objects.equals(vendorId, timeBook.vendorId) &&
            Objects.equals(name, timeBook.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(vendorId, name);
    }
}
