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

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_Family")
public class SceneMain_Family_Task extends BaseScene implements Scene {
    @JsonIgnore
    @Override
    public float getPriority() {
        return 1.0f;
    }

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\back.png";
    private static String PathTask1 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\task1.png";
    private static String PathTask2 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\task2.png";
    private static String PathTask3 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\task3.png";
    private static String PathTask4 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\task4.png";

    private static String PathRightdoor = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\rightDoor.png";
    private static String PathGoLeft = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\goLeft.png";
    private static String PathCancle = System.getProperty("user.dir") + "\\opencv\\scene\\family\\task\\cancle.png";


    @Override
    public void back() throws AWTException {
        if (checkHas(PathCancle, AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathCancle, AiManage.getInstance().getCheckPoint(),new Point(0,270));
            ThreadUtil.sleep(2000);
        }

        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(PathEnter, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathEnter, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                continue;
            }
            if (checkHas(PathRightdoor, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathGoLeft, AiManage.getInstance().getCheckPoint(), new Point(-100, -70));
                ThreadUtil.sleep(5000);
            }else {
                moveToClick(PathGoLeft, AiManage.getInstance().getCheckPoint(), new Point(430, -70));
                ThreadUtil.sleep(5000);
            }
        }
    }

    @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 < 20; i++) {
            //重复20次就算完成 TODO ice 优化更好的逻辑
            if (checkHas(PathTask1, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathTask1, AiManage.getInstance().getCheckPoint(),new Point(0,270));
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathTask2, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathTask2, AiManage.getInstance().getCheckPoint(),new Point(0,270));
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathTask3, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathTask3, AiManage.getInstance().getCheckPoint(),new Point(0,270));
                ThreadUtil.sleep(2000);
            }
            if (checkHas(PathTask4, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathTask4, AiManage.getInstance().getCheckPoint(),new Point(0,270));
                ThreadUtil.sleep(2000);
            }

            if (checkHas(PathCancle, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathCancle, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
            }
        }
        getRecord().getData().setDone(true);
    }

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

}
