import { readFileAndParse } from '../util'
import { FILENAME } from '../../consts'

export interface DicQuenchQuality {
    // id
    readonly id: number;
    // 装备品质
    readonly quality: number;
    // 品相
    readonly grade: number;
    // 单属性最小值
    readonly singleRatioMin: number;
    // 单属性最大值
    readonly singleRatioMax: number;
    // 初始是否可以随机出
    readonly initialAvailable: number;
    // 暴击率
    readonly critProbability: number;
    // 暴击效果
    readonly critEffect: number;
}

export const dicQuenchRangeByQualityAndGrade = new Map<string, { min: number, max: number, randMin: number, randMax: number }>();
export const dicQuenchRangeByQuality = new Map<number, { min: number, max: number, randMin: number, randMax: number }>(); // quality => {}
export const dicQuenchByQuality = new Map<number, Map<number, DicQuenchQuality>>(); // quality => grade => dic
export function loadQuenchQuality() {
    dicQuenchByQuality.clear();
    dicQuenchRangeByQuality.clear();
    dicQuenchRangeByQualityAndGrade.clear();
    let arr = readFileAndParse(FILENAME.DIC_QUENCH_QUALITY);

    arr.forEach(o => {
        if(o.initialAvailable == 1) {
        }


        if(!dicQuenchRangeByQuality.has(o.quality)) {
            dicQuenchRangeByQuality.set(o.quality, { min: o.singleRatioMin, max: o.singleRatioMax, randMin: o.singleRatioMin, randMax: o.singleRatioMax });
        } else {
            if(o.singleRatioMin < dicQuenchRangeByQuality.get(o.quality).min) {
                dicQuenchRangeByQuality.get(o.quality).min = o.singleRatioMin;
            }
            if(o.singleRatioMax > dicQuenchRangeByQuality.get(o.quality).max) {
                dicQuenchRangeByQuality.get(o.quality).max = o.singleRatioMax;
            }
            if(o.singleRatioMin < dicQuenchRangeByQuality.get(o.quality).randMin && o.initialAvailable == 1) {
                dicQuenchRangeByQuality.get(o.quality).randMin = o.singleRatioMin;
            }
            if(o.singleRatioMax > dicQuenchRangeByQuality.get(o.quality).randMax && o.initialAvailable == 1) {
                dicQuenchRangeByQuality.get(o.quality).randMax = o.singleRatioMax;
            }

        }
        dicQuenchRangeByQualityAndGrade.set(`${o.quality}_${o.grade}`, { min: o.singleRatioMin, max: o.singleRatioMax, randMin: o.singleRatioMin, randMax: o.singleRatioMax  });    


        if(!dicQuenchByQuality.has(o.quality)) {
            dicQuenchByQuality.set(o.quality, new Map<number, DicQuenchQuality>());
        }
        dicQuenchByQuality.get(o.quality).set(o.grade, o);
    });
    arr = undefined;
}