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

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 org.opencv.core.Point;

import java.awt.*;

/**
 * 福利
 */
@SceneAnnotation("SceneMain")
public class SceneMain_Welfare extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 6.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\back.png";
    private static String PathTatic = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\tatic.png";
    private static String PathTatic_dark = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\tatic_dark.png";
    private static String PathCrest = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\crest.png";
    private static String PathCrest_dark = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\crest_dark.png";
    private static String PathTake = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\take.png";
    private static String PathDown = System.getProperty("user.dir") + "\\opencv\\scene\\welfare\\down.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 {
        ThreadUtil.sleep(1000);
        moveToDrop(PathDown,AiManage.getInstance().getCheckPoint(),new Point(0,-40),new Point(0,-250));
        ThreadUtil.sleep(5000);
        if (checkHas(PathTatic_dark, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathTatic_dark, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }
        if (checkHas(PathTatic, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathTake, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            randomToClick();
            ThreadUtil.sleep(2000);
        }
        if (checkHas(PathCrest_dark, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathCrest_dark, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }
        if (checkHas(PathCrest, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathTake, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
            randomToClick();
            ThreadUtil.sleep(2000);
        }

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

    }

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

}
