import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqJump, ResJump } from "../../shared/protocols/peijiancangku/PtlJump";
import { HongDianChange } from "../hongdian/fun";

export default async function (call: ApiCall<ReqJump, ResJump>) {
    let db = await G.mongodb.cPlayerInfo('peijiancangku').findOne({ uid: call.uid, type: 'peijiancangku' });

    if (db?.index == G.gc.peijiancangku.jumpWarehouse.index) return call.errorCode(-1);

    await PlayerFun.checkNeedIsMeet(call, G.gc.peijiancangku.jumpWarehouse.need);
    await PlayerFun.cutNeed(call, G.gc.peijiancangku.jumpWarehouse.need);
    await PlayerFun.sendPrize(call, G.gc.peijiancangku.jumpWarehouse.prize);

    G.mongodb.cPlayerInfo('peijiancangku').updateOne(
        { uid: call.uid, type: 'peijiancangku' },
        { $set: { index: G.gc.peijiancangku.jumpWarehouse.index } },
        { upsert: true }
    );

    HongDianChange.sendChangeKey(call.uid, ['taskhd', 'huodonghd'])

    call.succ({});
}