from datetime import timedelta

from mower.utils import config
from mower.utils.email import notify
from mower.utils.graph import SceneGraphSolver
from mower.utils.scene import Scene


class Headhunting(SceneGraphSolver):
    solver_name = "每日赠送单抽"
    solver_max_duration = timedelta(minutes=1)

    def transition(self) -> bool:
        if (scene := self.scene()) == Scene.HEADHUNTING:
            if config.recog.match("sign_in/headhunting/available")[0] >= 0.9:
                self.tap("pull_once")
            else:
                notify("今日赠送单抽已抽完")
                return True
        elif scene == Scene.HEADHUNTING_FREE_CONFIRM:
            self.tap("double_confirm/main", x_rate=1)
        elif scene == Scene.HEADHUNTING_RESULT:
            notify("成功抽完赠送单抽")
            return True
        else:
            self.scene_graph_step(Scene.HEADHUNTING)
