import { ApiCall } from "tsrpc";
import { HuoDongFun } from "../../../public/huodongfun";
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/zixuanlibao/PtlOpen";

export default async function (call: ApiCall<ReqOpen, ResOpen>) {
    let _hdinfo = await HuoDongFun.getHdidInfo(call, call.req.hdid)
    if (!_hdinfo || Object.keys(_hdinfo).length <= 0) {
        // 无此活动
        return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
    }

    let _dbType: `zixuanlibao${number}` = `zixuanlibao${call.req.hdid}`
    let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType });

    call.succ({
        rec: db?.rec || {},
        hdinfo: _hdinfo
    });
}