/**
 * Workflow API Models
 * Models for workflow configuration and management
 */

export type ExecutionType = 'SEQUENTIAL' | 'PARALLEL';
export type CompletionCriteria = 'ALL' | 'ANY' | 'THRESHOLD';
export type RejectionHandling = 'FAIL_REQUEST' | 'RETRY_STAGE' | 'ESCALATE';

export interface DepartmentApproval {
  departmentCode: string;
  departmentName: string;
  canDelegate: boolean;
  timeoutDays?: number;
}

export interface WorkflowStage {
  stageId: string;
  stageName: string;
  stageOrder: number;
  executionType: ExecutionType;
  requiredApprovals: DepartmentApproval[];
  completionCriteria: CompletionCriteria;
  threshold?: number;
  timeoutDays?: number;
  rejectionHandling: RejectionHandling;
  escalationDepartment?: string;
  metadata?: Record<string, any>;
}

export interface CreateWorkflowDto {
  name: string;
  workflowType: string;
  description?: string;
  stages: WorkflowStage[];
  onSuccessActions?: string[];
  onFailureActions?: string[];
  metadata?: Record<string, any>;
  createdBy?: string;
}

export interface UpdateWorkflowDto {
  name?: string;
  description?: string;
  stages?: WorkflowStage[];
  isActive?: boolean;
  metadata?: Record<string, any>;
}

export interface WorkflowResponseDto {
  id: string;
  name: string;
  workflowType: string;
  description?: string;
  definition: {
    stages: WorkflowStage[];
    onSuccessActions?: string[];
    onFailureActions?: string[];
  };
  isActive: boolean;
  version: number;
  metadata?: Record<string, any>;
  createdBy?: string;
  createdAt: string;
  updatedAt: string;
}

export interface WorkflowPreviewDto {
  id: string;
  name: string;
  description?: string;
  workflowType: string;
  stages: WorkflowStagePreviewDto[];
  isActive: boolean;
}

export interface WorkflowStagePreviewDto {
  stageId: string;
  stageName: string;
  description?: string;
  departmentCode: string;
  departmentName: string;
  stageOrder: number;
  isRequired: boolean;
}

export interface WorkflowValidationResultDto {
  isValid: boolean;
  errors?: string[];
  warnings?: string[];
}

export interface PaginatedWorkflowsResponse {
  data: WorkflowResponseDto[];
  total: number;
  page: number;
  limit: number;
  totalPages: number;
  hasNextPage: boolean;
}
