/**
 * Industry-to-Sector Mapping
 *
 * Maps the 24 industry keys used during onboarding to 12 sector categories.
 * Sectors drive transaction-type config, appointment-type seeding, and
 * dashboard terminology.
 */

// ── Sector Keys ──────────────────────────────────────────────────────────

export const SECTOR_KEYS = [
  "health_care",
  "beauty_wellness",
  "food_hospitality",
  "retail_services",
  "property_facilities",
  "mobility_automotive",
  "home_services_trades",
  "education",
  "events_venues",
  "pet_services",
  "nonprofit_community",
  "public_sector",
] as const;

export type SectorKey = (typeof SECTOR_KEYS)[number];

// ── Industry → Sector Map ────────────────────────────────────────────────

export const INDUSTRY_TO_SECTOR: Record<string, SectorKey> = {
  // Health & Care
  healthcare: "health_care",
  dental: "health_care",
  physio: "health_care",
  "labs-diagnostics": "health_care",
  telehealth: "health_care",
  optometry: "health_care",
  pharmacy: "health_care",

  // Beauty & Wellness
  "beauty-wellness": "beauty_wellness",
  aesthetics: "beauty_wellness",
  "medical-spas": "beauty_wellness",

  // Food, Hospitality & Stays
  "food-hospitality": "food_hospitality",
  "restaurants-cafes": "food_hospitality",
  "hotels-accommodation": "food_hospitality",

  // Retail & Services (also the fallback sector)
  "retail-services": "retail_services",
  other: "retail_services",

  // Property & Facilities
  "property-facilities": "property_facilities",

  // Mobility & Automotive
  "mobility-industry": "mobility_automotive",
  "vehicle-rental": "mobility_automotive",

  // Home Services & Trades
  "home-services-trades": "home_services_trades",

  // Education
  education: "education",
  "sports-academies": "education",

  // Events & Venues
  "events-venues": "events_venues",

  // Pet Services
  "pet-services": "pet_services",
  vet: "pet_services",

  // Nonprofit & Community
  "nonprofit-community": "nonprofit_community",

  // Public Sector
  "public-sector": "public_sector",
};

// ── Display Names (EN / AR) ──────────────────────────────────────────────

export const SECTOR_DISPLAY_NAMES: Record<
  SectorKey,
  { en: string; ar: string }
> = {
  health_care: { en: "Health & Care", ar: "الصحة والرعاية" },
  beauty_wellness: { en: "Beauty & Wellness", ar: "الجمال والعافية" },
  food_hospitality: {
    en: "Food, Hospitality & Stays",
    ar: "المطاعم والضيافة والإقامة",
  },
  retail_services: { en: "Retail & Services", ar: "التجزئة والخدمات" },
  property_facilities: {
    en: "Property & Facilities",
    ar: "العقارات والمرافق",
  },
  mobility_automotive: {
    en: "Mobility & Automotive",
    ar: "التنقل والسيارات",
  },
  home_services_trades: {
    en: "Home Services & Trades",
    ar: "خدمات المنزل والحرف",
  },
  education: { en: "Education", ar: "التعليم" },
  events_venues: { en: "Events & Venues", ar: "الفعاليات والأماكن" },
  pet_services: {
    en: "Pet Services",
    ar: "خدمات الحيوانات الأليفة",
  },
  nonprofit_community: {
    en: "Nonprofit & Community",
    ar: "المنظمات غير الربحية والمجتمع",
  },
  public_sector: { en: "Public Sector", ar: "القطاع العام" },
};

// ── Helper Functions ─────────────────────────────────────────────────────

/**
 * Resolve an industry key (from org onboarding) to its parent sector.
 * Returns `'retail_services'` for unknown / null / undefined keys.
 */
export function getSectorForIndustry(
  industryKey: string | null | undefined,
): SectorKey {
  if (!industryKey) return "retail_services";
  return INDUSTRY_TO_SECTOR[industryKey] ?? "retail_services";
}

/**
 * Reverse lookup — all industry keys that belong to a given sector.
 */
export function getIndustriesForSector(sectorKey: SectorKey): string[] {
  return Object.entries(INDUSTRY_TO_SECTOR)
    .filter(([, sector]) => sector === sectorKey)
    .map(([industry]) => industry);
}
