import { IstanbulPluginOptions } from 'vite-plugin-istanbul';

interface CoverageSummaryData {
    lines: Totals;
    statements: Totals;
    branches: Totals;
    functions: Totals;
}

declare class CoverageSummary {
    constructor(data: CoverageSummary | CoverageSummaryData);
    merge(obj: CoverageSummary): CoverageSummary;
    toJSON(): CoverageSummaryData;
    isEmpty(): boolean;
    data: CoverageSummaryData;
    lines: Totals;
    statements: Totals;
    branches: Totals;
    functions: Totals;
}

interface Location {
    line: number;
    column: number;
}

interface Range {
    start: Location;
    end: Location;
}

interface BranchMapping {
    loc: Range;
    type: string;
    locations: Range[];
    line: number;
}

interface FunctionMapping {
    name: string;
    decl: Range;
    loc: Range;
    line: number;
}

interface FileCoverageData {
    path: string;
    statementMap: { [key: string]: Range };
    fnMap: { [key: string]: FunctionMapping };
    branchMap: { [key: string]: BranchMapping };
    s: { [key: string]: number };
    f: { [key: string]: number };
    b: { [key: string]: number[] };
}

interface Totals {
    total: number;
    covered: number;
    skipped: number;
    pct: number;
}

interface Coverage {
    covered: number;
    total: number;
    coverage: number;
}

declare class FileCoverage implements FileCoverageData {
    constructor(data: string | FileCoverage | FileCoverageData);
    merge(other: FileCoverageData): void;
    getBranchCoverageByLine(): { [line: number]: Coverage };
    getLineCoverage(): { [line: number]: number };
    getUncoveredLines(): number[];
    resetHits(): void;
    computeBranchTotals(): Totals;
    computeSimpleTotals(): Totals;
    toSummary(): CoverageSummary;
    toJSON(): object;

    data: FileCoverageData;
    path: string;
    statementMap: { [key: string]: Range };
    fnMap: { [key: string]: FunctionMapping };
    branchMap: { [key: string]: BranchMapping };
    s: { [key: string]: number };
    f: { [key: string]: number };
    b: { [key: string]: number[] };
}

interface IstanbulOptionsBabel {
    cwd?: string;
    include?: string[];
    exclude?: string[];
    extension?: string[];
    excludeNodeModules?: boolean;
    ignoreClassMethods?: string[];
    useInlineSourceMaps?: boolean;
    inputSourceMap?: object;
    nycrcPath?: string;
    onCover?: (fileName: string, fileCoverage: FileCoverage) => unknown;
    fileName?: string;
}
interface AddonOptionsBabel {
    istanbul?: IstanbulOptionsBabel;
}
interface AddonOptionsVite {
    istanbul?: IstanbulPluginOptions;
}
type AddonOptionsWebpack = {
    istanbul?: {
        cwd?: string;
        nycrcPath?: string;
        include?: string[];
        exclude?: string[];
        extension?: string[];
    };
};

export type { AddonOptionsBabel, AddonOptionsVite, AddonOptionsWebpack };
