package com.sencorsta.rabs.obj.ai.scene.fight;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Week;
import cn.hutool.core.thread.ThreadUtil;
import com.sencorsta.rabs.annotation.SceneAnnotation;
import com.sencorsta.rabs.obj.ai.AiManage;
import com.sencorsta.rabs.obj.ai.api.BaseScene;
import com.sencorsta.rabs.obj.ai.api.Scene;
import org.opencv.core.Point;

import java.awt.AWTException;
import java.util.Calendar;

/**
 * 无尽
 */
@SceneAnnotation("SceneMain_Fight")
public class SceneMain_Fight_Endless extends BaseScene implements Scene {
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\back.png";
    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\enter.png";

    private static String PathToLogin = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\toLogin.png";
    private static String PathLogin = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\login.png";
    private static String PathOk = System.getProperty("user.dir") + "\\opencv\\scene\\fight\\endless\\ok.png";


    @Override
    public void back() throws AWTException {
        moveToClick(PathBack, AiManage.getInstance().getCheckPoint());
    }

    @Override
    public void open() throws AWTException {
        while (AiManage.getInstance().isRunning() && !check()) {
            AiManage.getInstance().updateWindow();
            ThreadUtil.sleep(2000);
            if (checkHas(PathEnter, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint());
                continue;
            }

            if (checkHas(PathToLogin, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathToLogin, AiManage.getInstance().getCheckPoint());
                continue;
            }

            if (checkHas(PathLogin, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathLogin, AiManage.getInstance().getCheckPoint(), new Point(-50, -200));
                ThreadUtil.sleep(2000);
                moveToClick(PathLogin, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                moveToClick(PathOk, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(3000);
                continue;
            }


        }
    }

    @Override
    public boolean check() throws AWTException {
        if (checkHas(PathCheck, AiManage.getInstance().getCheckPoint())) {
            return true;
        }
        return false;
    }

    @Override
    public void think() throws AWTException {
    }


    @Override
    public boolean isDone() {
        return hasChildDone();
    }

    /**
     * 是否开启
     */
    @Override
    public boolean isOpen() {
        int weekDay = DateUtil.dayOfWeek(DateUtil.date());
        if (weekDay == Calendar.MONDAY||weekDay == Calendar.SUNDAY) {
            return false;
        }
        return true;
    }

}
