import { Application, ChannelService } from 'pinus';
import { resetPvpSeasonTime, guildActivityStart, gateActivityEnd, cityActivityEnd, raceActivityEnd, guildActivitySchedule, auctionSchedule } from '../../../services/timeTaskService';
import PvpDefenseType from '../../../db/PvpDefense';
import { DicGuildActivity } from '../../../pubUtils/dictionary/DicGuildActivity';
import { reloadResources } from '../../../pubUtils/data';
import { setMarquee, cancelMarquee } from '../../../services/gmService';
import { setDicAuctionTime, setDicGuildActivity } from '../../../services/guildActivityService';
import { setWeek } from '../../../pubUtils/timeUtil';

export default function (app: Application) {
    return new SystimerRemote(app);
}

export class SystimerRemote {

    constructor(private app: Application) {
        this.app = app;
        this.channelService = app.get('channelService');
    }
    private channelService: ChannelService;

    public async resetPvpSeasonTime(day: number) {
        return await resetPvpSeasonTime(day);
    }

    public async guildActivityStart(dicGuildActivity: DicGuildActivity) {
        return await guildActivityStart(dicGuildActivity);
    }

    public async gateActivityEnd() {
        return await gateActivityEnd();
    }

    public async cityActivityEnd() {
        return await cityActivityEnd();
    }

    public async raceActivityEnd() {
        return await raceActivityEnd();
    }
        
    /**
     * 重载json资源
     */
    public async reloadResources() {
        reloadResources();
    }

    /**
     * @description 设置跑马灯配置
     * @param code 跑马灯唯一code
     */
    public async setMarquee(code: string) {
        return await setMarquee(code);
    }

    public async cancelMarquee(code: string) {
        return await cancelMarquee(code);
    }

    /**
     * 改变字典表中的军团活动开始时间&持续时间
     * @param {number} aid 活动 
     * @param {number} startSeconds 从现在开始几秒后开启活动
     * @param {number} endSeconds 从开始之后几秒后结束活动
     */
     public async setDicGuildActivity(now: number, aid: number, startSeconds: number, endSeconds: number) {
        setDicGuildActivity(now, aid, startSeconds, endSeconds);
    }

    /**
     * 改变字典表中的拍卖行时间
     */
     public async setDicAuctionTime(startTime: number, endActivity: number, startGuild: number, endGuild: number, startWorld: number, endWorld: number) {
        setDicAuctionTime(startTime, endActivity, startGuild, endGuild, startWorld, endWorld);
    }

    public async setGuildActivitySchedule() {
        await guildActivitySchedule();
    }

    public async setAuctionSchedule() {
        auctionSchedule();
    }

    /**
     * !! 注意，这条函数会改变内存时间，影响甚大，请考虑清楚后使用
     */
     async setDay(week: number) {
        setWeek(week);
    }
}
