/**
 * Workflow Email Service Factory
 * 
 * Factory pattern to get the appropriate email service based on workflow type.
 * This ensures that each workflow type uses its own dedicated service,
 * preventing cross-workflow breakage.
 * 
 * To add a new workflow type:
 * 1. Create a new service file (e.g., `newWorkflowEmail.service.ts`)
 * 2. Implement IWorkflowEmailService interface
 * 3. Register it in this factory's getService method
 */

import { IWorkflowEmailService } from './workflowEmail.interface';
import { dealerClaimEmailService } from './dealerClaimEmail.service';
import logger from '@utils/logger';

class WorkflowEmailServiceFactory {
  /**
   * Get the appropriate email service for a workflow type
   * 
   * @param workflowType - The type of workflow (e.g., 'CLAIM_MANAGEMENT', 'CUSTOM', etc.)
   * @returns The appropriate email service implementation
   */
  getService(workflowType: string): IWorkflowEmailService {
    switch (workflowType) {
      case 'CLAIM_MANAGEMENT':
        return dealerClaimEmailService;
      
      // Add new workflow types here:
      // case 'NEW_WORKFLOW_TYPE':
      //   return newWorkflowEmailService;
      
      default:
        // For custom workflows or unknown types, return null
        // The caller should handle this and use default logic
        logger.warn(`[WorkflowEmailFactory] Unknown workflow type: ${workflowType}, using default email logic`);
        return null as any; // Return null, caller will handle default logic
    }
  }

  /**
   * Check if a workflow type has a dedicated email service
   */
  hasDedicatedService(workflowType: string): boolean {
    return workflowType === 'CLAIM_MANAGEMENT';
    // Add new workflow types here:
    // || workflowType === 'NEW_WORKFLOW_TYPE';
  }
}

export const workflowEmailServiceFactory = new WorkflowEmailServiceFactory();

