/**
 * Utility functions for generating user-friendly job status messages and toast notifications
 */

export interface StatusMessageConfig {
  message: string;
  type: 'success' | 'info' | 'warning' | 'error';
  showToast: boolean;
}

/**
 * Get user-friendly message and toast configuration for job status updates
 */
export function getStatusMessageConfig(
  status: string, 
  jobTitle?: string, 
  customMessage?: string
): StatusMessageConfig {
  const title = jobTitle ? `"${jobTitle}"` : 'Job';
  const fallbackMessage = customMessage || '';
  
  switch (status) {
    case 'created':
      return {
        message: `${title} has been created and queued for processing`,
        type: 'info',
        showToast: true
      };
      
    case 'ingesting':
      return {
        message: `${title} is being ingested and prepared for AI processing`,
        type: 'info', 
        showToast: true
      };
      
    case 'ai_processing':
      return {
        message: `${title} is being processed by AI to generate accessibility features`,
        type: 'info',
        showToast: true
      };
      
    case 'pending_qc':
      return {
        message: `${title} is ready for quality control review`,
        type: 'info',
        showToast: true
      };
      
    case 'approved_english':
    case 'approved_source':
      return {
        message: `${title} source content has been approved - starting translation`,
        type: 'success',
        showToast: true
      };

    case 'rejected':
      return {
        message: `${title} has been rejected and requires revision`,
        type: 'warning',
        showToast: true
      };
      
    case 'translating':
      return {
        message: `${title} is being translated and transcreated into requested languages`,
        type: 'info',
        showToast: true
      };
      
    case 'tts_generating':
      return {
        message: `${title} is generating audio descriptions with text-to-speech`,
        type: 'info',
        showToast: true
      };
      
    case 'pending_final_review':
      return {
        message: `${title} is ready for final review before completion`,
        type: 'info',
        showToast: true
      };
      
    case 'qc_feedback':
      return {
        message: `${title} final review has been rejected - requires changes`,
        type: 'warning',
        showToast: true
      };
      
    case 'completed':
      return {
        message: `${title} has been completed successfully! 🎉 All files are ready for download`,
        type: 'success',
        showToast: true
      };
      
    default:
      return {
        message: fallbackMessage || `${title} status updated to ${status}`,
        type: 'info',
        showToast: !!fallbackMessage
      };
  }
}

/**
 * Get a shorter status message for progress updates
 */
export function getProgressMessage(status: string, progress?: number): string {
  const progressText = progress !== undefined ? ` (${progress}%)` : '';
  
  switch (status) {
    case 'ingesting':
      return `Ingesting video${progressText}`;
    case 'ai_processing':
      return `AI processing${progressText}`;
    case 'translating':
      return `Translating content${progressText}`;
    case 'tts_generating':
      return `Generating audio${progressText}`;
    default:
      return status.replace(/_/g, ' ');
  }
}