import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ShiwuFun } from '../../public/shiwu';
import { ReqRecast, ResRecast } from "../../shared/protocols/shiwu/PtlRecast";
import { ShiwuShared } from '../../shared/public/shiwu';

export default async function (call: ApiCall<ReqRecast, ResRecast>) {

    let shiwu = await ShiwuFun.getShiwu(call, call.req._id);
    if (!shiwu) return call.error(globalThis.lng.shiwu_3);
    if (!shiwu.zhuanshu) return call.error(globalThis.lng.shiwu_4);

    let need = ShiwuShared.getRecastNeed(call.req.needType);
    await PlayerFun.checkNeedIsMeet(call, need);

    ShiwuFun.randomZhuanshu(shiwu);
    await PlayerFun.cutNeed(call, need);
    await ShiwuFun.changeShiwuAttr(call, shiwu, { zhuanshu: shiwu.zhuanshu });

    call.succ({});
}