#!/usr/bin/env python3

import sys
from datetime import datetime, timedelta

from mower.utils import path

if __name__ == "__main__":
    if len(sys.argv) == 2:
        path.global_space = sys.argv[1]

    import logging

    from mower.utils import config
    from mower.utils.log import dhlr
    from mower.utils.scheduler import scheduler

    dhlr.setLevel(logging.INFO)
    conf = config.conf
    now = datetime.now()

    scheduler.register_one_time(
        solver="mower.solvers.mini_base.MiniBase",
        time=datetime.now(),
    )

    if conf.sign_in.enable:
        scheduler.register_daily(
            solver="mower.solvers.sign_in.SignInManager",
            offset=timedelta(hours=4),
            priority=15,
        )
    if conf.visit_friend:
        scheduler.register_daily(
            solver="mower.solvers.credit.CreditSolver",
            offset=timedelta(hours=4),
            priority=16,
        )
    if conf.report_enable:
        scheduler.register_daily(
            solver="mower.solvers.infra.report.ReportSolver",
            offset=timedelta(hours=4),
            priority=17,
        )
    if conf.switch_assistants:
        scheduler.register_daily(
            solver="mower.solvers.infra.switch_assistants.SwitchAssistantsSolver",
            offset=timedelta(hours=4),
            priority=18,
        )
    if conf.skland_enable:
        scheduler.register_daily(
            solver="mower.solvers.skland.SKLand",
            offset=timedelta(hours=3),
            priority=19,
        )
    if conf.check_mail_enable:
        scheduler.register_daily(
            solver="mower.solvers.mail.MailSolver",
            offset=timedelta(hours=4),
            priority=20,
        )
    if conf.maa_credit_fight:
        scheduler.register_daily(
            solver="mower.solvers.fight.credit_fight.CreditFight",
            offset=timedelta(hours=4),
            priority=21,
        )
    if conf.maa_depot_enable:
        scheduler.register_daily(
            solver="mower.solvers.trade_token.TradeTokenSolver",
            offset=timedelta(hours=4),
            priority=22,
        )
    if conf.enable_party:
        scheduler.register_periodic(
            solver="mower.solvers.infra.clue.ClueManager",
            interval=timedelta(hours=1),
            priority=24,
        )
    if conf.recruit_enable:
        scheduler.register_periodic(
            solver="mower.solvers.recruit.RecruitSolver",
            interval=timedelta(hours=config.conf.recruit_gap),
            priority=25,
        )
    if conf.work_enable:
        scheduler.register_periodic(
            solver="mower.solvers.fight.copy_works.CopyWorksSolver",
            interval=timedelta(hours=config.conf.maa_gap),
            priority=26,
        )
    if conf.maa_enable:
        scheduler.register_periodic(
            solver="mower.solvers.operation.OperationManager",
            interval=timedelta(hours=config.conf.maa_gap),
            priority=27,
        )
    if conf.maa_depot_enable:
        scheduler.register_periodic(
            solver="mower.solvers.depotREC.depotREC",
            interval=timedelta(hours=config.conf.maa_gap),
            priority=28,
        )
    scheduler.register_periodic(
        solver="mower.solvers.mission.MissionSolver",
        interval=timedelta(hours=config.conf.maa_gap),
        priority=29,
    )

    scheduler.schedule()
