import { ApiCall } from "tsrpc";
import { KuangDongfun } from "../../public/kuangdong";
import { ReqGetPrize, ResGetPrize } from "../../shared/protocols/kuangdong/PtlGetPrize";
import { HongDianChange } from "../hongdian/fun";

export default async function (call: ApiCall<ReqGetPrize, ResGetPrize>) {
    let _kdInfo;
    let conf = G.gc.land[call.req.hdid.toString()];

    if (conf.public_map == 1){
        _kdInfo = await KuangDongfun.getKaiCaiInfo(call.req.hdid)
    }else {
        _kdInfo = await KuangDongfun.getKaiCaiInfo(call.req.hdid, call.uid)
    }

    /**没有建筑信息 */
    if (!_kdInfo) {
        return call.error('', { code: -1, message: globalThis.lng.kudangdong_7 })
    }

    /**不能放弃别人的 */
    if (_kdInfo.uid != call.uid) {
        return call.error('', { code: -2, message: globalThis.lng.kudangdong_8 })
    }

    /**结算 函数内部已经发了奖励 */
    let _prize = await KuangDongfun.getKuangDongPrize(call.req.hdid, _kdInfo, { msgtype: 4})
    HongDianChange.sendChangeKey(call.uid, ['kuangdonghd'])


    call.succ({
        prize: _prize
    });
}