from mower.solvers.base_schedule import BaseSchedulerSolver
from mower.utils import config
from mower.utils.log import logger
from mower.utils.scheduler import scheduler


class BaseManager:
    solver_name = "基建"

    def run(self):
        if config.base_scheduler is None:
            config.base_scheduler = BaseSchedulerSolver()
            if err_msg := config.base_scheduler.validate_plan():
                logger.error(err_msg)
                return True
        while True:
            config.base_scheduler.run()
            if len(config.tasks) > 0:
                config.tasks.sort(key=lambda x: x.time)
                logger.info("基建任务：")
                for t in config.tasks:
                    logger.info(t)
                scheduler.register_one_time(
                    "mower.solvers.base_manager.BaseManager", config.tasks[0].time
                )
                break
        return True
