import { ApiCall } from "tsrpc";
import { GongHuiFun } from '../../public/gonghui/gonghui';
import { GHManage } from '../../public/gonghui/manage';
import { PlayerFun } from '../../public/player';
import { ReqChange, ResChange } from "../../shared/protocols/gonghui/PtlChange";

export default async function (call: ApiCall<ReqChange, ResChange>) {

    if (call.conn.gud.ghLevel > 2) return call.error(globalThis.lng.gonghui_1);
    if (call.conn.gud.ghLevel != 1 && call.req.name) return call.error(globalThis.lng.gonghui_4);

    await GongHuiFun.checkSetArgs(call.req);

    if (call.req.name){
        await PlayerFun.checkNeedIsMeet(call, G.gc.shili_com.changeNameNeed);

        await PlayerFun.cutNeed(call, G.gc.shili_com.changeNameNeed);
    }


    (await GHManage.getGH(call.conn.gud.ghId)).updateSetting(call.req);

    call.succ(call.req);

}