from mower.solvers.infra.enter_room import EnterRoomSolver
from mower.utils.graph import SceneGraphSolver
from mower.utils.log import logger
from mower.utils.recognize import Scene

from .utils import clue_cls


class DailySolver(SceneGraphSolver):
    def run(self) -> None:
        self.success = False
        super().run()

    def transition(self) -> bool:
        if (scene := self.scene()) == Scene.INFRA_DETAILS:
            self.tap((725, 850))
        elif scene == Scene.INFRA_CONFIDENTIAL:
            # 检查是否领过线索
            daily_scope = ((1815, 200), (1895, 250))
            if self.find("clue/badge_new", scope=daily_scope) and not self.success:
                self.tap((1800, 270))
            else:
                return True
        elif scene == Scene.CLUE_DAILY:
            if not self.find(
                "clue/icon_notification", scope=((1400, 0), (1920, 400))
            ) and (clue := clue_cls("daily")):
                logger.info(f"领取今日线索（{clue}号）")
                self.tap_element("clue/button_get")
            else:
                # 今日线索已领取，点X退出
                self.tap((1484, 152))
                self.success = True
        elif scene in self.waiting_scene:
            self.waiting_solver()
        else:
            EnterRoomSolver().run("meeting", detail=False)
