// src/core/errors.ts

/** Base class for all errors originating from the @flowlab/data library */
export class FlowLabDataError extends Error {
  constructor(message: string) {
      super(message);
      this.name = this.constructor.name;
      // Ensure stack trace is captured correctly (needed for V8)
      if (Error.captureStackTrace) {
          Error.captureStackTrace(this, this.constructor);
      }
  }
}

/** Error related to pipeline configuration */
export class ConfigurationError extends FlowLabDataError {
  public readonly configPath?: string;
  public readonly reason?: string;

  constructor(message: string, configPath?: string, reason?: string) {
      super(message);
      this.configPath = configPath;
      this.reason = reason;
  }
}

/** Error related to a specific component (Extractor, Transformer, Loader) */
export class ComponentError extends FlowLabDataError {
  public readonly componentName?: string;
  public readonly originalError?: Error;

  constructor(message: string, componentName?: string, originalError?: Error) {
      super(message);
      this.componentName = componentName;
      this.originalError = originalError;
  }
}

/** Error occurring during the execution of a pipeline run */
export class PipelineRunError extends FlowLabDataError {
   public readonly pipelineId?: string;
   public readonly runId?: string;
   public readonly originalError?: Error;

   constructor(message: string, pipelineId?: string, runId?: string, originalError?: Error) {
       super(message);
       this.pipelineId = pipelineId;
       this.runId = runId;
       this.originalError = originalError;
   }
}