/**
 * Utility functions for identifying and handling Claim Management requests
 * Works with both old format (templateType: 'claim-management') and new format (workflowType: 'CLAIM_MANAGEMENT')
 */

/**
 * Check if a request is a Claim Management request
 * Supports both old and new backend formats
 */
export function isClaimManagementRequest(request: any): boolean {
  if (!request) return false;

  // New format: Check workflowType
  if (request.workflowType === 'CLAIM_MANAGEMENT') {
    return true;
  }

  // Old format: Check templateType (for backward compatibility)
  if (request.templateType === 'claim-management' || request.template === 'claim-management') {
    return true;
  }

  // Check template name/code
  if (request.templateName === 'Claim Management' || request.templateCode === 'CLAIM_MANAGEMENT') {
    return true;
  }

  return false;
}

/**
 * Get workflow type from request
 * Returns 'CLAIM_MANAGEMENT' for claim requests, 'NON_TEMPLATIZED' for others
 */
export function getWorkflowType(request: any): string {
  if (!request) return 'NON_TEMPLATIZED';

  // New format
  if (request.workflowType) {
    return request.workflowType;
  }

  // Old format: Map templateType to workflowType
  if (request.templateType === 'claim-management' || request.template === 'claim-management') {
    return 'CLAIM_MANAGEMENT';
  }

  return 'NON_TEMPLATIZED';
}

/**
 * Check if request needs claim-specific UI components
 */
export function shouldUseClaimManagementUI(request: any): boolean {
  return isClaimManagementRequest(request);
}

