/**
 * Catalog Utilities
 * Helper functions for catalog operations
 */

import type {
  InternetPlanCatalogItem,
  InternetAddonCatalogItem,
  InternetInstallationCatalogItem,
  SimCatalogProduct,
  VpnCatalogProduct,
} from "@customer-portal/domain/catalog";

type CatalogProduct =
  | InternetPlanCatalogItem
  | InternetAddonCatalogItem
  | InternetInstallationCatalogItem
  | SimCatalogProduct
  | VpnCatalogProduct;

/**
 * Business logic transformations (filtering, sorting, etc.) are handled server-side.
 * These helpers are deliberately limited to presentation concerns only.
 */

/**
 * Get product category display name
 */
export function getCategoryDisplayName(category: string): string {
  const categoryNames: Record<string, string> = {
    internet: "Internet Plans",
    sim: "SIM Plans",
    vpn: "VPN Services",
  };

  return categoryNames[category] || category;
}

/**
 * Check if product is recommended (works with InternetPlan type)
 */
export function isProductRecommended(product: CatalogProduct): boolean {
  if ("catalogMetadata" in product && product.catalogMetadata) {
    const metadata = product.catalogMetadata as { isRecommended?: boolean };
    return Boolean(metadata.isRecommended);
  }
  return false;
}

/**
 * Calculate savings percentage (if applicable)
 */
export function calculateSavings(originalPrice: number, currentPrice: number): number {
  if (originalPrice <= currentPrice) return 0;
  return Math.round(((originalPrice - currentPrice) / originalPrice) * 100);
}
