from mower.utils.graph import SceneGraphSolver
from mower.utils.recognize import Scene

from .utils.utils import get_money_num


class RogueShopSolver(SceneGraphSolver):
    solver_name = "诡意行商投资"

    def transition(self):
        if (scene := self.scene()) == Scene.ROGUE_SHOP:
            if self.animation(((0, 150), (1920, 880)), interval=0.2, ratio=0.2):
                return
            if (
                self.find("rogue/shop/full_1")
                or self.find("rogue/shop/stop_invest")
                or get_money_num() == 0
            ):
                self.tap((1800, 830))
                return
            self.tap((750, 360))

        elif scene == Scene.ROGUE_INVESTMENT_PORTAL:
            if (
                self.find("rogue/shop/full_2")
                or self.find("rogue/shop/stop_service")
                or get_money_num() == 0
            ):
                self.ctap((1200, 750), 3)
                return
            self.tap("rogue/shop/investment_portal")

        elif scene == Scene.ROGUE_INVESTMENT:
            if (
                self.find("rogue/shop/full_3")
                or self.find("rogue/shop/restricted_investment")
                or get_money_num() == 0
            ):
                self.ctap((940, 740), 3)
                return
            self.tap((1300, 750))

        elif scene in self.waiting_scene:
            self.waiting_solver()
        else:
            return True
