import { Application, ChannelService, FrontendSession, RemoterClass, HandlerService, pinus, } from 'pinus';
import { resResult } from '../../../pubUtils/util';
import { STATUS } from '../../../consts';
import { handleComBtlProgress, _addToSearchingTeams } from '../../../services/comBattleService';
import { MemComBtlTeam } from '../../../domain/battleField/ComBattleTeamField';
import { errlogger } from '../../../util/logger';
import { saveComBattleMemory } from '../../../services/log/memoryLogService';

export default function (app: Application) {
    new HandlerService(app, {});
    return new ComBattleRemote(app);
}

export class ComBattleRemote {
    bossHp = 10000;

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

    private channelService: ChannelService;

    public async checkMyTeam(roleId: string ) {
        try {
            let teamMap: Map<string, MemComBtlTeam> = this.app.get('teamMap');
            let hasMyTeam = false;
            for(let [,team] of teamMap) {
                if(team.roleIds.indexOf(roleId) > -1) {
                    hasMyTeam = true; break;
                }
            }
            return hasMyTeam
        } catch(e) {
            errlogger.error(`remote ${__filename} \n ${e.stack}`);
        }
    }


    public async addToSearchingTeams(teamCode: string, roleId: string, sid: string) {
        try {
            await _addToSearchingTeams(teamCode, roleId, sid);
        } catch(e) {
            errlogger.error(`remote ${__filename} \n ${e.stack}`);
        }
    }

    public saveComBattleMemory() {
        try {
            return saveComBattleMemory();
        } catch(e) {
            errlogger.error(`remote ${__filename} \n ${e.stack}`);
        }
    }
}