package com.example.iot_controlhost.utils.control.temperature.strategy;

import com.example.iot_controlhost.utils.global.AutoModelSet;
import com.example.iot_controlhost.utils.global.RoomSensor;
import com.example.iot_controlhost.utils.global.RoomSetting;
import com.example.iot_controlhost.utils.global.SpinnerList;
import com.example.iot_controlhost.utils.global.Variable;
import com.example.iot_controlhost.utils.log.MyLog;

/**
 * @Description 按档位控制 温差范围为Variable.AUTO_DO_NOTHING_TEMPERATURE_NORMAL
 * 需要考虑室内外温度 保温逻辑
 * @Author DuanKaiji
 * @CreateTime 2023年10月24日 09:36:38
 */
public class GearControl extends ControlStrategy {
    private static boolean needHeatToTarget = false;
    private static boolean needColdToTarget = false;

    @Override
    public void controlAlgorithm(double curTemperature, double targetTemperature) {
        String autoTemperatureHeat = AutoModelSet.getAutoTemperatureHeat();
        String autoTemperatureCool = AutoModelSet.getAutoTemperatureCool();
        if (curTemperature < targetTemperature - Variable.AUTO_DO_NOTHING_TEMPERATURE_NORMAL
                || curTemperature < targetTemperature && needHeatToTarget) {
            MyLog.auto("普通模式：正在升温");
            needHeatToTarget = true;
            if (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[0])) {
                //均不可用
            } else if (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[1])) {
                //地暖
                gear = 5;
            } else if (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[2])) {
                //空调
                temp = 30;
                mode = 0;
            } else if (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[3])) {
                //空调和地暖
                temp = 30;
                mode = 0;
                gear = 5;
            }
        } else if (curTemperature > targetTemperature + Variable.AUTO_DO_NOTHING_TEMPERATURE_NORMAL
                || curTemperature > targetTemperature && needColdToTarget) {
            MyLog.auto("普通模式：正在降温");
            needColdToTarget = true;
            if (autoTemperatureCool.equals(SpinnerList.TEMPERATURE_COOL[1])) {
                //空调
                mode = 2;
                temp = 17;
                MyLog.auto("普通模式：开启空调制冷17度");
            } else {
                //均不可用
                MyLog.auto("普通模式：理应降温，但降温设备设置为‘均不可用’");
            }
        } else {
            //在正常范围内
            needHeatToTarget = false;
            needColdToTarget = false;
            // 地暖逻辑 2024年9月9日 13:32:21 去掉普通模式地暖保温逻辑
//            double outDoorTemperature = RoomSensor.outdoorTHSensor.getTemperature();
//            if (//可以用地暖
//                (autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[1]) || autoTemperatureHeat.equals(SpinnerList.TEMPERATURE_HEAT[3]))
//                    //并且：当前温度低于目标温度
//                    && curTemperature < targetTemperature) {
//                //保温-重定向地暖档位-根据与目标温差
//                double bias = targetTemperature - curTemperature;
//                if (bias > 0.7) {
//                    gear = 4;
//                } else if (bias >= 0.5) {
//                    gear = 3;
//                } else if (bias >= 0.4) {
//                    gear = 2;
//                } else if (bias >= 0.3) {
//                    gear = 1;
//                }
//                //保温-重定向地暖档位-根据室内外温差
//                if (curTemperature > outDoorTemperature + 3) {
//                    if (curTemperature > outDoorTemperature + 10 && gear <= 1) {
//                        //室外温度与室内温度偏差10度及以上，地暖2档保温
//                        gear = 2;
//                    } else if (curTemperature > outDoorTemperature + 3 && gear == 0) {
//                        //室外温度与室内温度偏差3度及以上，地暖1档保温
//                        gear = 1;
//                        MyLog.auto("普通模式：室外温度与室内温度偏差3度及以上，" + RoomSetting.getFloorName() + "1档保温");
//                    }
//                } else if (curTemperature < outDoorTemperature - 5) {
//                    //比室外温度低3度以上
//                    gear = 0;
//                    MyLog.auto("普通模式：室外温度比室内高5度或以上，" + RoomSetting.getFloorName() + "关闭");
//                }
//            }
        }
    }

}
