/**
 * Handler and Queue Types
 * Shared types for handler system and queue operations
 */

// Generic execution context - decoupled from service implementations
export interface ExecutionContext {
  type: 'http' | 'queue' | 'scheduled' | 'event';
  metadata: {
    source?: string;
    jobId?: string;
    attempts?: number;
    timestamp?: number;
    traceId?: string;
    [key: string]: unknown;
  };
}

// Simple handler interface
export interface IHandler {
  execute(operation: string, input: unknown, context: ExecutionContext): Promise<unknown>;
}

// Job handler type for queue operations
export interface JobHandler<TPayload = unknown, TResult = unknown> {
  (payload: TPayload): Promise<TResult>;
}

// Type-safe wrapper for creating job handlers
export type TypedJobHandler<TPayload, TResult = unknown> = (payload: TPayload) => Promise<TResult>;

// Scheduled job configuration
export interface ScheduledJob<T = unknown> {
  type: string;
  operation: string;
  payload?: T;
  cronPattern: string;
  priority?: number;
  description?: string;
  immediately?: boolean;
  delay?: number;
}

// Handler configuration
export interface HandlerConfig {
  [operation: string]: JobHandler;
}

// Handler configuration with schedule
export interface HandlerConfigWithSchedule {
  name: string;
  operations: Record<string, JobHandler>;
  scheduledJobs?: ScheduledJob[];
}

// Handler metadata for registry
export interface HandlerMetadata {
  name: string;
  version?: string;
  description?: string;
  operations: string[];
  scheduledJobs?: ScheduledJob[];
}

// Operation metadata for decorators
export interface OperationMetadata {
  name: string;
  schedules?: string[];
  operation?: string;
  description?: string;
  validation?: (input: unknown) => boolean;
}

