/**
 * CI pipeline status
 */
export enum PipelineStatus {
  PENDING = "pending",
  RUNNING = "running",
  SUCCESS = "success",
  FAILURE = "failure",
  KILLED = "killed",
  ERROR = "error",
  SKIPPED = "skipped",
  BLOCKED = "blocked",
}

/**
 * Pipeline information
 */
export interface PipelineInfo {
  number: number;
  status: PipelineStatus;
  event: string;
  branch: string;
  commit: string;
  started?: number;
  finished?: number;
  error?: string;
}

/**
 * CI failure diagnosis result
 */
export interface FailureDiagnosis {
  category: FailureCategory;
  message: string;
  suggestion: string;
  details?: string;
}

/**
 * Common CI failure categories
 */
export enum FailureCategory {
  LINT = "lint",
  TYPE_CHECK = "type-check",
  TEST = "test",
  BUILD = "build",
  SECURITY = "security",
  UNKNOWN = "unknown",
}

/**
 * Options for waiting on pipeline completion
 */
export interface PipelineWaitOptions {
  /** Timeout in seconds (default: 1800 = 30 minutes) */
  timeout?: number;
  /** Poll interval in seconds (default: 10) */
  pollInterval?: number;
  /** Whether to fetch logs on failure (default: true) */
  fetchLogsOnFailure?: boolean;
}

/**
 * Result of waiting for pipeline
 */
export interface PipelineWaitResult {
  success: boolean;
  pipeline: PipelineInfo;
  logs?: string;
  diagnosis?: FailureDiagnosis;
}

/**
 * Custom error for CI operations
 */
export class CIOperationError extends Error {
  constructor(
    message: string,
    public readonly operation: string,
    public readonly cause?: Error
  ) {
    super(message);
    this.name = "CIOperationError";
  }
}
