/**
 * RepoPilot exception hierarchy.
 */

export class RepoPilotError extends Error {
  constructor(message: string) {
    super(message);
    this.name = "RepoPilotError";
  }
}

export class ParseError extends RepoPilotError {
  constructor(
    public readonly filePath: string,
    public readonly reason: string,
  ) {
    super(`Failed to parse ${filePath}: ${reason}`);
    this.name = "ParseError";
  }
}

export class IndexCorruptedError extends RepoPilotError {
  constructor(
    public readonly path: string,
    public readonly reason: string,
  ) {
    super(`Corrupted index at ${path}: ${reason}`);
    this.name = "IndexCorruptedError";
  }
}

export class IndexVersionError extends RepoPilotError {
  constructor(
    public readonly expected: number,
    public readonly found: number,
  ) {
    super(
      `Index version ${found} incompatible with SDK version (expects ${expected})`,
    );
    this.name = "IndexVersionError";
  }
}

export class PluginError extends RepoPilotError {
  constructor(
    public readonly pluginName: string,
    public readonly reason: string,
  ) {
    super(`Plugin '${pluginName}' error: ${reason}`);
    this.name = "PluginError";
  }
}
