import { ApiCall } from "tsrpc";
import { FightFun } from '../../public/fight';
import { ReqFight, ResFight } from "../../shared/protocols/user/PtlFight";

export default async function (call: ApiCall<ReqFight, ResFight>) {

    let my = await FightFun.getPlayerFightData(call.uid);

    if (Object.keys(my.roles).length < 1) return call.error('', { code: -1, message: globalThis.lng.user_2 });

    let he = await FightFun.getPlayerFightData(call.req.uid);

    if (!he) return call.error('', { code: -2, message: globalThis.lng.user_3 });
    if (Object.keys(he.roles).length < 1) return call.error('', { code: -3, message: globalThis.lng.user_4 });

    let result = FightFun.fight([my, he]);

    call.succ({
        result: result
    });
}