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

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.AWTException;

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

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\mail\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\mail\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\mail\\back.png";
    private static String PathOneButton = System.getProperty("user.dir") + "\\opencv\\scene\\mail\\oneButton.png";
    private static String PathExtTake = System.getProperty("user.dir") + "\\opencv\\scene\\mail\\extTake.png";
    private static String PathExtClose = System.getProperty("user.dir") + "\\opencv\\scene\\mail\\extClose.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 {
        if (checkHas(PathOneButton, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathOneButton, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(4000);
            randomToClick();
            ThreadUtil.sleep(6000);

            if (checkHas(PathExtTake,AiManage.getInstance().getCheckPoint())){
                moveToClick(PathExtClose, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(3000);
            }

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

    }

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

}
