export type FileImportFailureCode =
  | "SOURCE_LOCKED_OR_UNREADABLE"
  | "SOURCE_SCHEMA_UNSUPPORTED"
  | "FILE_READ_ERROR";

export interface FileImportWarning {
  code: string;
  message_code: string;
  severity: "info" | "warning" | "error";
  source_file_id?: string;
  details?: Record<string, number | string | boolean>;
}

/** A source file could not be imported as a whole and must be retried by the scanner. */
export class FileImportError extends Error {
  readonly code: FileImportFailureCode;
  readonly warnings: FileImportWarning[];

  constructor(code: FileImportFailureCode, message = code, warnings: FileImportWarning[] = []) {
    super(message);
    this.name = "FileImportError";
    this.code = code;
    this.warnings = warnings;
  }
}

export function isFileImportError(error: unknown): error is FileImportError {
  return error instanceof FileImportError;
}
