import { ApiCall } from "tsrpc";
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/niudanji/PtlOpen";
import { player } from '../../../shared/protocols/user/type';

export default async function (call: ApiCall<ReqOpen, ResOpen>) {

    let db = await G.mongodb.cEvent('niudanji').findOne({ uid: call.uid, type: 'niudanji' });

    call.succ({
        hasNum: pay2num(call.conn.gud),
        useNum: db?.useNum || 0,
        logs: (await G.mongodb.collection('any').findOne({ type: 'niudanlog' }))?.data || []
    });
}

export function pay2num(player: player) {
    return Math.floor(player.payExp / G.gc.niudanji.pay2num);
}