// Type declarations for jso-symbolicate
// Project: https://www.javascriptobfuscator.com/Docs/Symbolication.aspx

export interface IdentifierMapEntry {
    Mangled?: string;
    Original?: string;
    mangled?: string;
    original?: string;
    from?: string;
    to?: string;
    short?: string;
    long?: string;
}

export type MapSource =
    | IdentifierMapEntry[]
    | Record<string, string>
    | string
    | null
    | undefined;

export interface DemangleOptions {
    /** "replace" (default): substitute the original name. "annotate": keep the mangled name and append /* original *​/. */
    style?: "replace" | "annotate";
}

export interface DemangleStats {
    stack: string;
    hits: number;
    perLine: number[];
}

/**
 * Build a flat {mangled: original} lookup by merging one or more map sources.
 * Accepts arrays of {Mangled, Original} entries, plain objects, or the
 * "mangled=original\n..." block-text form.
 */
export function buildLookup(...sources: MapSource[]): Record<string, string>;

/**
 * Demangle a stack trace string by substituting mangled identifiers with their
 * original names. Lines that don't match are returned unchanged.
 */
export function demangleStack(
    stack: string,
    lookup: Record<string, string>,
    options?: DemangleOptions
): string;

/**
 * Demangle a stack trace and return statistics: total substitution count and
 * per-line counts. Useful for detecting wrong-map cases in CI (hits === 0 with
 * a non-empty map almost always means the map and the stack are from different
 * builds).
 */
export function demangleStackWithStats(
    stack: string,
    lookup: Record<string, string>,
    options?: DemangleOptions
): DemangleStats;
