/**
 * 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;

  // Handle case where request is the full response object { request, claimDetails, ... }
  const req = request.request || request;

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

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

  // Check template name/code
  if (req.templateName === 'Claim Management' || req.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';

  // Handle wrapped response
  const req = request.request || request;

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

  // Old format: Map templateType to workflowType
  if (req.templateType === 'claim-management' || req.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);
}

