// ═══════════════════════════════════════════════════════════
// Pipeline Types — from CONTRACTS.md §1.4
// ═══════════════════════════════════════════════════════════

export type PipelineStatus = "active" | "paused" | "completed" | "failed" | "archived";
export type Priority = "critical" | "high" | "medium" | "low";
export type PipelineTemplate = "mcp-server-standard" | "mcp-server-minimal" | "mcp-server-enterprise";

export type PipelineStage =
  | "intake"
  | "scaffolding"
  | "building"
  | "testing"
  | "review"
  | "staging"
  | "production"
  | "published";

export type StageStatus = "pending" | "active" | "completed" | "skipped" | "failed";

export interface Pipeline {
  id: string;
  name: string;
  slug: string;
  template: PipelineTemplate;
  platform: string;
  currentStage: PipelineStage;
  status: PipelineStatus;
  priority: Priority;
  createdBy: string;
  assigneeId: string | null;
  config: Record<string, unknown>;
  metadata: Record<string, unknown>;
  slaDeadline: string | null;
  startedAt: string;
  completedAt: string | null;
  createdAt: string;
  updatedAt: string;
}

export interface PipelineStageRecord {
  id: string;
  pipelineId: string;
  stageName: PipelineStage;
  stageOrder: number;
  status: StageStatus;
  requiresApproval: boolean;
  approvalType: "manual" | "auto" | "conditional";
  autoAdvance: boolean;
  validationRules: ValidationRule[];
  enteredAt: string | null;
  completedAt: string | null;
  durationSeconds: number | null;
  createdAt: string;
}

export interface ValidationRule {
  type: "test_coverage" | "tests_passing" | "required_asset" | "approval_count" | "custom";
  config: Record<string, unknown>;
}

/** Dashboard aggregation */
export interface DashboardSummary {
  pipelines: {
    active: number;
    paused: number;
    completed: number;
    failed: number;
  };
  tasks: import("./task.js").TaskStats;
  agents: {
    total: number;
    active: number;
    idle: number;
    error: number;
    offline: number;
  };
  recentActivity: import("./audit.js").AuditEntry[];
  slaStatus: {
    onTrack: number;
    warning: number;
    breached: number;
  };
}

/** Pipeline detail state for MCP resources */
export interface PipelineDetailState {
  pipeline: Pipeline;
  stages: PipelineStageRecord[];
  currentTasks: import("./task.js").Task[];
  recentAssets: import("./asset.js").Asset[];
  blockers: import("./task.js").BlockerInfo[];
  timeline: import("./audit.js").AuditEntry[];
}

/** Pipeline template config */
export interface PipelineTemplateConfig {
  id: PipelineTemplate;
  name: string;
  description: string;
  stages: PipelineStage[];
  defaultConfig: Record<string, unknown>;
  requiredAssets: import("./asset.js").AssetType[];
  validationRules: ValidationRule[];
}
