import axios from 'axios';
import { env } from 'process';
import { player } from '../shared/protocols/user/type';


export class G123 {
    static sendUserLevelUp(gud: player) {
        if (!env.SERVER_ID) return;
        this.sendEvent('level_up', {
            game_server_id: env.SERVER_ID.toString(),
            ctwid: gud.bindUid,
            timestamp: G.date.getTime(),
            level: gud.lv,
            data: {
                game_server_id: env.SERVER_ID.toString(),
                game_user_id: gud.bindUid,
                role: {
                    id: gud.uid,
                    name: gud.name,
                    exp: gud.nexp.toString(),
                    vip_level: gud.vip.toString(),
                    vip_exp: gud.payExp.toString(),
                    virtual_balance: Object.fromEntries(Object.keys(G.gc.attr).difference(['nexp', 'payExp', 'shilifrd']).map(k => [k, `${(gud[k] || 0)}`])),
                    custom: {}
                },
                custom: {
                    device_id: '',
                    physical_server: `http://game${env.SERVER_ID}`
                }
            }
        });
    }
    static sendEvent(type: string, data: any) {
        axios.post(`http://server-tool:7456/server/postEvent`, {
            type: type,
            data: data
        });
    }
}