import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqSlot, ResSlot } from "../../shared/protocols/slzd/PtlSlot";
import { PublicShared } from '../../shared/public/public';
import { HongDianChange } from "../hongdian/fun";

export default async function (call: ApiCall<ReqSlot, ResSlot>) {

    await PlayerFun.checkNeedIsMeet(call, G.gc.slzd.slotNeed);
    await PlayerFun.cutNeed(call, G.gc.slzd.slotNeed);

    let prize = PublicShared.randomDropGroup(G.gc.slzd.slotDrop);

    await PlayerFun.sendPrize(call, prize);

    HongDianChange.sendChangeKey(call.uid, ['slzdhd'])

    call.succ({
        prize: prize
    });

    G.mongodb.collection('slzdGh').updateOne(
        { ghid: call.conn.gud.ghId },
        { $push: { soltLog: { $each: [{ name: call.conn.gud.name, prize: prize }], $slice: -30 } } }
    );
}