export class UserShared {
    /**获取头像之类id */
    static getInfoId(type: 'head' | 'headFrame' | 'chatFrame' | 'model', id: string, pos?: string) {
        return Array.from(arguments).filter(s => s != '').join('_');
    }

    // todo active始终为空，暂时获取对应的avtive，解决打包上线的圣诞版本，
    //  后续要理清数据格式，填入playerinfo的active，包括user/infoOpen接口的返回
    static getActive(fmtId, player, type, id?) {
        switch (type) {
            case 'head':
                return {[fmtId]: player.head?.time}
            case 'headFrame':
                return {[fmtId]: player.headFrames[id]}
            case 'chatFrame':
                return {[fmtId]: player.chatFrames[id]}
            case 'model':
                return {[fmtId]: player.model?.[id]?.time}
        }
        return {}
    }

    /**
     * 判断头像之类是否激活
     * @param id 请使用 UserShared.getInfo 转化后的id
     */
    static chechIsActive(fmtId: string, collection: Partial<{ lv: number, vip: number, lsyx: k_v<number>, model: k_v<any>, active: k_v<number>, heroskin: k_v<any>; }>) {

        const [type, id] = fmtId.split('_');
        const jsonName = 'player' + type.slice(0, 1).toLocaleUpperCase() + type.slice(1);
        const json = G.gc[jsonName] as any;
        const conf: _gcType['playerHead'] = json[id];

        if (conf.cond[0] == 'lv') return collection.lv >= conf.cond[1];
        else if (conf.cond[0] == 'vip') return collection.vip >= conf.cond[1];
        else if (conf.cond[0] == 'hero') return collection.lsyx[conf.cond[1]] > 0;
        // else if (conf.cond[0] == 'time') return collection.active[fmtId] == -1 || collection.active[fmtId] > G.time;
        else if (conf.cond[0] == 'time') return conf.cond[1] == -1 || collection.active?.[fmtId] > G.time;
        else if (conf.cond[0] == 'model') return Object.values(collection.model).find(i => i.id == conf.cond[1]);
        else if (conf.cond[0] == 'heroskin') return conf.cond[1] in collection.heroskin;
        else return false;
    }
}