import {ApiCall} from "tsrpc";
import {WangZheRongYaofun} from "../../public/wzry";
import {ReqAutoBaoMing, ResAutoBaoMing} from "../../shared/protocols/wzry/PtlAutoBaoMing";

export default async function (call: ApiCall<ReqAutoBaoMing, ResAutoBaoMing>) {
    if (call.conn.gud.lv < G.gc.openCond.wzrybm.and.lv) {
        // 等级不足
        return call.error('', {code: -1/* , message: globalThis.lng.wzry_1 */});
    }

    let _mydata = await WangZheRongYaofun.getMyData(call);
    if (_mydata.isauto == call.req.auto) {
        return call.succ({mydata: _mydata})
    }

    if ([0, 1].includes(call.req.auto)) {
        _mydata.isauto = call.req.auto
    }
    let _setData = {
        isauto: _mydata.isauto
    };
    G.mongodb.collection('playerInfo', 'wzry').updateOne({uid: call.conn.uid, type: 'wzry'}, {$set: _setData});
    call.succ({mydata: _mydata});
}