import { VOCAB } from '@/lib/white-label/constants';

/**
 * Job Queue Type Definitions
 * Async job processing for ${VOCAB.factory} and other heavy operations
 */

export type JobStatus = 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled';
export type JobPriority = 'critical' | 'high' | 'normal' | 'low';

export interface Job<T = unknown> {
  id: string;
  type: string;
  payload: T;
  priority: JobPriority;
  status: JobStatus;
  attempts: number;
  maxAttempts: number;
  createdAt: Date;
  startedAt?: Date;
  completedAt?: Date;
  processAfter?: Date;
  result?: unknown;
  error?: string;
  metadata?: Record<string, unknown>;
}

export interface JobHandler<T = unknown, R = unknown> {
  type: string;
  process: (payload: T, job: Job<T>) => Promise<R>;
  onComplete?: (job: Job<T>, result: R) => Promise<void>;
  onFail?: (job: Job<T>, error: Error) => Promise<void>;
  maxAttempts?: number;
  timeout?: number;
}

export interface QueueConfig {
  name: string;
  concurrency: number;
  pollInterval: number;
  defaultMaxAttempts: number;
  retryDelay: (attempts: number) => number;
}

export interface JobQueueStats {
  pending: number;
  processing: number;
  completed: number;
  failed: number;
  avgProcessingTime: number;
}

// ${VOCAB.factory} specific job types
export interface GenerationJobPayload {
  requestId: string;
  prompt: string;
  context?: Record<string, unknown>;
  priority?: JobPriority;
}

export interface ValidationJobPayload {
  taskId: string;
  artifactIds: string[];
}

export interface DeploymentJobPayload {
  taskId: string;
  artifactIds: string[];
  environment: 'dev' | 'staging' | 'prod';
  approvedBy?: string;
}
