from mower.solvers.fight.battle_choose.battle_agent_choose import (
    BattleAgentChooseSolver,
)
from mower.solvers.fight.battle_choose.battle_fill_choose import BattleFillChooseSolver
from mower.solvers.fight.battle_choose.choose_support import ChooseSupportSolver
from mower.utils import config
from mower.utils.graph import SceneGraphSolver
from mower.utils.recognize import Scene


class SSSChooseSolver(SceneGraphSolver):
    solver_name = "保全选人"

    def run(self):
        copilot = config.works["sss"]
        opers = [oper.model_dump(exclude_none=True) for oper in copilot.opers]
        tool_men = copilot.tool_men.model_dump()
        blacklist = copilot.blacklist
        lack = BattleAgentChooseSolver().run(opers)[0]
        for profession, number in tool_men.items():
            BattleFillChooseSolver().run(profession, number, blacklist)
        super().run()
        ChooseSupportSolver().run(lack)

    def transition(self):
        if (scene := self.scene()) == Scene.OPERATOR_AGENT_SELECT:
            self.tap("choose_agent/battle_confirm")
        elif scene in self.waiting_scene:
            self.waiting_solver()
        elif scene == Scene.SSS_SQUAD:
            return True
