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_helper extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 3.0f;
    }

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

    private static String PathOneButton = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\helper\\oneButton.png";
    private static String PathChallenge = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\helper\\challenge.png";
    private static String PathOk = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\helper\\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;
            }
        }
    }

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

    @Override
    public void think() throws AWTException {
        moveToClick(PathOneButton,AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);
        int countTemp=30;
        while (countTemp>0&&AiManage.getInstance().isRunning() && !checkHas(PathOk,AiManage.getInstance().getCheckPoint())){
            ThreadUtil.sleep(2000);
            countTemp--;
        }
        ThreadUtil.sleep(5000);
        moveToClick(PathOk,AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);
        moveToClick(PathOk,AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);

        while (AiManage.getInstance().isRunning() && !checkHas(PathChallenge,AiManage.getInstance().getCheckPoint())){
            ThreadUtil.sleep(2000);
        }
        moveToClick(PathChallenge,AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

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

        countTemp=30;
        while (countTemp>0&&AiManage.getInstance().isRunning() && !checkHas(PathOk,AiManage.getInstance().getCheckPoint())){
            ThreadUtil.sleep(2000);
            countTemp--;
        }
        ThreadUtil.sleep(5000);
        moveToClick(PathOk,AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);
        moveToClick(PathOk,AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

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

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

}
