import { PrewarmLevel } from "@normalized:N&&&tencentqianwebview/src/main/ets/model/PrewarmLevel&1.0.0";
class BjcCov {
    coverage: {
        [key: string]: string | number;
    };
    constructor(covData: object) {
        const gcv = "__coverage__";
        let coverage = globalThis[gcv] || (globalThis[gcv] = {});
        if (!coverage[covData.path] && true) {
            coverage[covData.path] = covData;
        }
        this.coverage = coverage[covData.path];
    }
    instrumentFunction(func: number) {
        this.coverage.functions[func].count++;
        this.coverage.functions[func].regions[0].count++;
    }
    instrumentRegion(func: number, region: number) {
        this.coverage.functions[func].regions[region].count++;
    }
    instrumentReturn(func: number, retIdx: number) {
        this.coverage.functions[func].returnes[retIdx].count++;
    }
    instrumentBranch(func: number, branch: number, trueOrFalse: boolean) {
        if (trueOrFalse) {
            this.coverage.functions[func].branches[branch].trueCount++;
            for (let r of Object.values(this.coverage.functions[func].branches[branch].group)) {
                if (r !== branch) {
                    this.coverage.functions[func].branches[r as number].falseCount++;
                }
            }
        }
        else {
            this.coverage.functions[func].branches[branch].falseCount++;
        }
    }
}
let bjccovms5u83ty = new BjcCov({ version: "bjc v1.0.0", versionCode: 10000, path: "tencentqianwebview/src/main/ets/internal/prewarm/PrewarmDedup.ets", hash: "2190c4c91f64695180c003f7de2d876aba26e00609cdb3d39a7b0b093897d146", lineCnt: 48, count: 0, projectPath: "", functions: { 0: { name: "PrewarmDedup.shouldRun", count: 0, regions: { 0: { startLoc: { line: 17, col: 3 }, endLoc: { line: 26, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 18, col: 41 }, endLoc: { line: 20, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 22, col: 28 }, endLoc: { line: 24, col: 6 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 25, col: 5 }, endLoc: { line: 26, col: 4 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 18, col: 9 }, endLoc: { line: 18, col: 39 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 1: { startLoc: { line: 22, col: 9 }, endLoc: { line: 22, col: 26 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 0 }, 1: { name: "PrewarmDedup.markDone", count: 0, regions: { 0: { startLoc: { line: 31, col: 3 }, endLoc: { line: 40, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 32, col: 41 }, endLoc: { line: 35, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 37, col: 43 }, endLoc: { line: 39, col: 6 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 32, col: 9 }, endLoc: { line: 32, col: 39 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 1: { startLoc: { line: 37, col: 9 }, endLoc: { line: 37, col: 41 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 1 }, 2: { name: "PrewarmDedup.reset", count: 0, regions: { 0: { startLoc: { line: 43, col: 3 }, endLoc: { line: 46, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 44, col: 5 }, endLoc: { line: 46, col: 4 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 2 } }, exeLine: { 0: 1, 1: 10, 2: 11, 3: 12, 4: 17, 5: 18, 6: 19, 7: 21, 8: 22, 9: 23, 10: 25, 11: 31, 12: 32, 13: 33, 14: 34, 15: 36, 16: 37, 17: 38, 18: 43, 19: 44, 20: 45 } });
/**
 * 单调去重状态（design.md Decision 4）。
 *
 * - `MINIMAL`：全局只做一次（`minimalDone`）。
 * - `LIGHT` / `HEAVY`：每 bizType 记录已达最高档；低于等于已达档则不再执行。
 * - 不允许降级重热；仅 manifest version 变化时 `reset()` 整体重置。
 */
export class PrewarmDedup {
    private reached: Map<string, PrewarmLevel> = new Map();
    private minimalDone: boolean = false;
    /**
     * 判断本次 `(level, bizType)` 是否应执行（未被去重）。
     */
    public shouldRun(level: PrewarmLevel, bizType: string): boolean {
        bjccovms5u83ty.instrumentFunction(0);
        if (level === PrewarmLevel.MINIMAL) {
            bjccovms5u83ty.instrumentBranch(0, 0, true);
            bjccovms5u83ty.instrumentRegion(0, 1);
            return !this.minimalDone;
        }
        else {
            bjccovms5u83ty.instrumentBranch(0, 0, false);
        }
        const cur: PrewarmLevel | undefined = this.reached.get(bizType);
        if (cur === undefined) {
            bjccovms5u83ty.instrumentBranch(0, 1, true);
            bjccovms5u83ty.instrumentRegion(0, 2);
            return true;
        }
        else {
            bjccovms5u83ty.instrumentBranch(0, 1, false);
        }
        bjccovms5u83ty.instrumentRegion(0, 3);
        return level > cur;
    }
    /**
     * 标记 `(level, bizType)` 已完成，更新已达档（单调不降）。
     */
    public markDone(level: PrewarmLevel, bizType: string): void {
        bjccovms5u83ty.instrumentFunction(1);
        if (level === PrewarmLevel.MINIMAL) {
            bjccovms5u83ty.instrumentBranch(1, 0, true);
            bjccovms5u83ty.instrumentRegion(1, 1);
            this.minimalDone = true;
            return;
        }
        else {
            bjccovms5u83ty.instrumentBranch(1, 0, false);
        }
        const cur: PrewarmLevel | undefined = this.reached.get(bizType);
        if (cur === undefined || level > cur) {
            bjccovms5u83ty.instrumentBranch(1, 1, true);
            bjccovms5u83ty.instrumentRegion(1, 2);
            this.reached.set(bizType, level);
        }
        else /** 整体重置（manifest version 变化时调用）。 */ {
            bjccovms5u83ty.instrumentBranch(1, 1, false);
        }
    }
    /** 整体重置（manifest version 变化时调用）。 */
    public reset(): void {
        bjccovms5u83ty.instrumentFunction(2);
        bjccovms5u83ty.instrumentRegion(2, 1);
        this.reached.clear();
        this.minimalDone = false;
    }
}
