import { ApiCall } from "tsrpc";
import { PeijianFun } from '../../public/peijian';
import { PlayerFun } from '../../public/player';
import { ReqRm, ResRm } from "../../shared/protocols/peijian/PtlRm";

export default async function (call: ApiCall<ReqRm, ResRm>) {
    let peijians = (await PeijianFun.getPeijian(call, call.req.p_ids)).filter(peijian => !peijian.wearId && peijian.lv <= 1);
    if (peijians.length < call.req.p_ids.length) return call.errorCode(-1);

    let prize = peijians.map(p => G.gc.peijian[p.peijianId].rmPrize).reduce((a, b) => a.concat(b));

    await PlayerFun.cutPeijian(call, call.req.p_ids);

    prize = await PlayerFun.sendPrize(call, prize);

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