import { ApiCall } from "tsrpc";
import { ReqManage, ResManage } from "../../shared/protocols/gonghui/PtlManage";

export default async function (call: ApiCall<ReqManage, ResManage>) {
    if (call.conn.gud.ghLevel >= 3) return call.error(globalThis.lng.gonghui_1);
    let GHdata = await call.conn.gonghui
    const player = GHdata.data.players.find(p => p.uid == call.req.uid);

    if (!player) return call.error(globalThis.lng.gonghui_22);
    if (player.uid == call.uid) return call.error(globalThis.lng.gonghui_23);
    if (player.level == call.req.level) return call.error(globalThis.lng.gonghui_15);
    //管理只可以踢人
    if (call.conn.gud.ghLevel == 2 && (player.level == 1 || player.level == 2)) return call.error(globalThis.lng.gonghui_1);

    if (call.req.level > 0) {
        if (call.req.level == 1) GHdata.managePlayer(call.uid, player.level);
        GHdata.managePlayer(call.req.uid, call.req.level);
    } else {
        GHdata.delPlayer(call.req.uid);
    }

    call.succ({});
}