from mower.utils import config
from mower.utils import typealias as tp
from mower.utils.graph.utils import SceneGraphSolver
from mower.utils.scene import Scene

from .battle_agent_choose import BattleAgentChooseSolver
from .battle_fill_choose import BattleFillChooseSolver
from .check_current_team import CheckCurrentTeamSolver
from .choose_squad import ChooseSquadSolver


class BattleChooseSolver(SceneGraphSolver):
    solver_name = "战斗选人"

    def run(
        self,
        opers: tp.Opers = [],
        groups: tp.Groups = [],
        squad: int = 0,
        support: bool = True,
    ):
        """
        Args:
            opers: 干员列表
            groups: 干员组列表
            squad: 队伍编号
            support: 缺一个干员时是否选择支援
        """
        if squad:
            ChooseSquadSolver().run(squad)
        if CheckCurrentTeamSolver().run(opers, groups, support):
            return True
        num = 12 - BattleAgentChooseSolver().run(opers + groups)[1]
        if config.conf.choose.add_low_trust_opers:
            BattleFillChooseSolver().run("信赖值", num)
        super().run()
        return CheckCurrentTeamSolver().run(opers, groups, support)

    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()
        else:
            return True
