import { ApiCall } from "tsrpc";
import { XstaskFun } from '../../public/xstask';
import { ReqLvUp, ResLvUp } from "../../shared/protocols/xstask/PtlLvUp";

export default async function (call: ApiCall<ReqLvUp, ResLvUp>) {

    let info = await XstaskFun.getInfo(call.uid);
    let upConf = G.gc.xstaskcom.lv[info.lv + 1];

    if (!upConf) return call.error(globalThis.lng.xstask_3);

    let num = 0;
    for (let colour in info.finishNum) {
        num += info.finishNum[colour];
    }

    if (num < upConf.need) return call.errorCode(-1);

    XstaskFun.changeInfo(call.uid, { $inc: { lv: 1 } });

    call.succ({ lv: info.lv + 1 });
}