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

    private static String PathEnter = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\enter.png";
    private static String PathCheck = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\check.png";
    private static String PathBack = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\back.png";
    private static String PathAsk = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\ask.png";
    private static String PathSendAsk = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\sendAsk.png";
    private static String PathAskClose = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\askClose.png";
    private static String PathMemory = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\memory.png";
    private static String PathGive = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\give.png";
    private static String PathPiece1 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\piece1.png";
    private static String PathPiece2 = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\piece2.png";
    private static String PathPiece2Dark = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\piece2_dark.png";
    private static String PathPaper = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\paper.png";

    private static String PathRightdoor = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\rightDoor.png";
    private static String PathGoLeft = System.getProperty("user.dir") + "\\opencv\\scene\\family\\help\\goLeft.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(2000);
                continue;
            }

            if (checkHas(PathPaper, AiManage.getInstance().getCheckPoint())) {
                moveToClick(PathPaper, AiManage.getInstance().getCheckPoint(), new Point(300, 0));
                ThreadUtil.sleep(2000);
            }

            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 {
        moveToClick(PathAsk, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        moveToClick(PathSendAsk, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);


        moveToClick(PathMemory, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        while (AiManage.getInstance().isRunning() && checkHas(PathGive,AiManage.getInstance().getCheckPoint())){
            int count = getRecord().getData().getCount();
            if (count<3){
                moveToClick(PathGive, AiManage.getInstance().getCheckPoint());
                ThreadUtil.sleep(2000);
                randomToClick();
                ThreadUtil.sleep(2000);
            }else {
                break;
            }
        }

        moveToClick(PathAsk, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        moveToClick(PathPiece1, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);

        moveToClick(PathSendAsk, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);


        moveToClick(PathAsk, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(2000);

        if (checkHas(PathPiece2,AiManage.getInstance().getCheckPoint())) {
            moveToClick(PathPiece2, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(3000);
        }else {
            moveToClick(PathPiece2Dark, AiManage.getInstance().getCheckPoint());
            ThreadUtil.sleep(3000);
        }


        moveToClick(PathSendAsk, AiManage.getInstance().getCheckPoint());
        ThreadUtil.sleep(3000);


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

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

}
