import { ApiCall } from "tsrpc";
import { ReqApply, ResApply } from "../../shared/protocols/gonghui/PtlApply";
import { HongDianChange } from "../hongdian/fun";

export default async function (call: ApiCall<ReqApply, ResApply>) {
    if (call.conn.gud.ghLevel == 3) return call.error(globalThis.lng.gonghui_1);
    let GHdata = await call.conn.gonghui
    const index = GHdata.data.applyList.findIndex(a => a.uid == call.req.uid);

    if (index == -1) return call.error(globalThis.lng.gonghui_2);

    if (call.req.apply) {
        GHdata.apply(call.req.uid);
    } else {
        GHdata.data.applyList.splice(index, 1);
        GHdata.updateDb({ $set: { applyList: GHdata.data.applyList } });
    }
    HongDianChange.sendChangeKey(call.uid, ['gonghuihd'])

    call.succ({ message: "success", code: 0 });
}