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.graph import SceneGraphSolver
from mower.utils.log import logger
from mower.utils.recognize import Scene

from .utils import translate2


class SSSChooseSolver(SceneGraphSolver):
    def run(self, opers: list, tool_men: dict, blacklist: list):
        logger.info("Start: 保全选人")
        lack = BattleAgentChooseSolver().run(opers)
        for profession, number in tool_men.items():
            profession = self.translate(profession)
            BattleFillChooseSolver().run(profession, number, blacklist)
        super().run()
        ChooseSupportSolver().run(lack)
        return

    def translate(self, profession: str):
        if profession in translate2:
            return translate2[profession]
        return profession

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