import { BaseConnection } from 'tsrpc';
import { Wjjl } from '../../../module/collection_wjjl';
import { ActionLog } from '../../../public/actionLog/actionLog';


function getPeijianGteColor5ID(){
    var ids = [];
    for(let id in G.gc.peijian){
        if (G.gc.peijian[id].colour >= 5){
            ids.push(id);  
        }
    }
    return ids;
}
let peijianGteColor5ID;


export async function getFinished(conn: BaseConnection, types: string[]) {

    if(!peijianGteColor5ID){
        peijianGteColor5ID = getPeijianGteColor5ID();
        // console.log('peijianGteColor5ID',peijianGteColor5ID);
    }
    
    let obj: k_v<number> = {};
    for (let type of types) {
        if (type == 'power') obj[type] = await Wjjl.getVal(conn.uid, 'power');
        else if (conn.gud[type] != undefined) obj[type] = conn.gud[type];
        else if (type == 'use_attr_rmbmoney') obj[type] = await ActionLog.getRetainLog(conn.uid, 'use_attr_rmbmoney');
        else if (type == 'zccg') obj[type] = (await G.mongodb.collection('pata').findOne({ uid: conn.uid }))?.lv || 0;
        else if (type == 'equip_star_5') {
            obj[type] = await G.mongodb.collection('equip').count({ uid: conn.uid, star: { $gte: 5 } });
        } else if (type == 'peijian_colour_5') {
            obj[type] = await G.mongodb.collection('peijian').count({ uid: conn.uid, peijianId: { $in: peijianGteColor5ID } });
        }
    }

    return obj;
}