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

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\back.png";
    private static String PathRightdoor = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\rightDoor.png";
    private static String PathGoLeft = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\goLeft.png";

    private static String PathTime3 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\time3.png";
    private static String PathFind = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\find.png";
    private static String PathTake = System.getProperty("user.dir") + "\\opencv\\scene\\family\\out\\take.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());
                ThreadUtil.sleep(5000);
                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 {
        if (getRecord().getData().isDone()){
            return;
        }
        ThreadUtil.sleep(2000);
        if (checkHas(PathTime3, AiManage.getInstance().getCheckPoint())){
            moveToClick(PathTime3, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(2000);
        }
        moveToClick(PathFind, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(6000);

        moveToClick(PathTake, AiManage.getInstance().getCheckPoint(),new Point(0,-180));
        ThreadUtil.sleep(4000);

        java.awt.Point lastClickPoint = AiManage.getInstance().getLastClickPoint();
        lastClickPoint.setLocation(lastClickPoint.getX(),lastClickPoint.getY()+180);
        randomToClick();
        ThreadUtil.sleep(4000);


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

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

}
