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

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 com.sencorsta.rabs.util.ResettableData;

import java.awt.*;

/**
 * 琦玉任务
 */
@SceneAnnotation("SceneMain_Qiyu")
public class SceneMain_Qiyu_quest extends BaseScene implements Scene {
    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\enter.png";
    private static String PathEnter2 = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\enter2.png";
    private static String PathEnter3 = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\enter3.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\back.png";
    private static String PathFinish = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\finish.png";
    private static String PathDailyJob = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\dailyJob.png";
    private static String PathList = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\list.png";
    private static String PathTake = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\take.png";
    private static String PathListBack = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\listBack.png";
    private static String PathRefersh = System.getProperty("user.dir") + "\\opencv\\scene\\qiyu\\quest\\refersh.png";

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

    @Override
    public void open() throws AWTException {
        while (AiManage.getInstance().isRunning() && !check()) {
            AiManage.getInstance().updateWindow();
            ThreadUtil.sleep(2000);
            if (checkHas(PathEnter3, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter3, AiManage.getInstance().getCheckPoint(), new org.opencv.core.Point(50, 0));
                ThreadUtil.sleep(2000);
                continue;
            }
//            if (checkHas(PathEnter, AiManage.getInstance().getCheckPoint())) {
//                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint(), new org.opencv.core.Point(-5, 20));
//                ThreadUtil.sleep(2000);
//                continue;
//            }
//            if (checkHas(PathEnter2, AiManage.getInstance().getCheckPoint())) {
//                moveToClick(PathEnter2, AiManage.getInstance().getCheckPoint(), new org.opencv.core.Point(0, -30));
//                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 {

        for (int i = 0; i < 4; i++) {
            ThreadUtil.sleep(1234);
            if (checkHas(PathEnter, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint(), new org.opencv.core.Point(-5, 20));
                ThreadUtil.sleep(3000);
                randomToClick();
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathFinish, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathFinish, AiManage.getInstance().getCheckPoint(), new org.opencv.core.Point(-5, 20));
                ThreadUtil.sleep(3000);
                randomToClick();
                ThreadUtil.sleep(2000);
            }
        }
        if (checkHas(PathDailyJob, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathDailyJob, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(3000);
            randomToClick();
        }

        if (checkHas(PathList, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathList, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            //最多点4次
            for (int i = 0; i < 4; i++) {
                if (checkHas(PathTake, AiManage.getInstance().getCheckPoint())) {
                    moveToClick(PathTake, AiManage.getInstance().getCheckPoint());
                } else {
                    moveToClick(PathRefersh, AiManage.getInstance().getCheckPoint());
                }
                ThreadUtil.sleep(2000);
            }
            moveToClick(PathListBack, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }
        getRecord().getData().setDone(true);
    }

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


    /**
     * 重置
     */
    @Override
    public ResettableData.ResetType getType() {
        return ResettableData.ResetType.SPECIAL_RULES;
    }
}
