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

import cn.hutool.core.thread.ThreadUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
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 java.awt.*;

/**
 * 琦玉任务
 */
@SceneAnnotation("SceneMain_Qiyu")
public class SceneMain_Qiyu_find extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 2.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\back.png";

    private static String PathEnter2 = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\enter2.png";
    private static String PathInfo = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\info.png";
    private static String PathGoon = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\goon.png";
    private static String PathStart = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\start.png";
    private static String PathOk = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\ok.png";
    private static String PathRewrad = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\find\\rewrad.png";


    @Override
    public void back() throws AWTException {
        while (AiManage.getInstance().isRunning() && !checkHas(PathOk, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathBack, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }
        ThreadUtil.sleep(2000);
        moveToClick(PathOk, AiManage.getInstance().getCheckPoint());
        int countTemp = 0;
        while (AiManage.getInstance().isRunning() && !checkHas(PathRewrad, AiManage.getInstance().getCheckPoint())) {
            countTemp++;
            ThreadUtil.sleep(2000);
            if (countTemp % 5 == 0) {
                moveToClick(PathOk, AiManage.getInstance().getCheckPoint());
            }
        }
        if (checkHas(PathOk, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathOk, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }
        ThreadUtil.sleep(15000);
        moveToClick(PathOk, AiManage.getInstance().getCheckPoint());

    }

    @Override
    public void open() throws AWTException {
        while (AiManage.getInstance().isRunning() && !check()) {
            AiManage.getInstance().updateWindow();
            ThreadUtil.sleep(2000);

            if (checkHas(PathEnter2, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter2, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                continue;
            }

            if (checkHas(PathEnter, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                continue;
            }
        }
    }

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

    @Override
    public void think() throws AWTException {

        ThreadUtil.sleep(4000);
        moveToClick(PathInfo, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        if (checkHas(PathGoon, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathGoon, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }

        if (checkHas(PathStart, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathStart, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }

        while (AiManage.getInstance().isRunning() && !checkHas(PathStart, AiManage.getInstance().getCheckPoint())) {
            ThreadUtil.sleep(1000);
        }

        getRecord().getData().setDone(true);
    }

    @Override
    public boolean isDone() {
        return getRecord().getData().isDone();
    }

}
