// Definitive mapping of ERP product descriptions to museum names.
// Priority order matters — first match wins (handles combo tickets).
// Combo tickets matching multiple museums split revenue/visits 50/50.

const MUSEUM_KEYWORDS: [string, string[]][] = [
  ['Revelation Exhibition', ['Revelation', 'الوحي']],
  ['Creation Story Museum', ['Creation Story', 'قصة الخلق']],
  ['Holy Quraan Museum', ['Holy Quraan', 'القرآن الكريم']],
  ['Trail To Hira Cave', ['Trail To Hira', 'غار حراء']],
  ['Makkah Greets Us', ['Makkah Greets']],
  ['Best of Creation', ['Best of Creation', 'خير الخلق']],
  ['VIP Experience', ['VIP Experience']],
];

export const MUSEUM_NAMES = MUSEUM_KEYWORDS.map(([name]) => name);

export interface MuseumMatch {
  museums: string[];
  split: number; // 1 = full, 0.5 = split between 2 museums
}

export function getMuseumsFromProduct(productDescription: string): MuseumMatch {
  const desc = productDescription.trim();
  const matched: string[] = [];

  for (const [museum, keywords] of MUSEUM_KEYWORDS) {
    for (const kw of keywords) {
      if (desc.includes(kw)) {
        matched.push(museum);
        break;
      }
    }
  }

  if (matched.length === 0) return { museums: ['Other'], split: 1 };
  if (matched.length === 1) return { museums: matched, split: 1 };

  // Multiple museums matched — split evenly
  return { museums: matched, split: 1 / matched.length };
}

// Static museum → district mapping
const MUSEUM_DISTRICT: Record<string, string> = {
  'Revelation Exhibition': 'Hiraa',
  'Holy Quraan Museum': 'Hiraa',
  'Trail To Hira Cave': 'Hiraa',
  'Makkah Greets Us': 'Hiraa',
  'VIP Experience': 'Hiraa',
  'Creation Story Museum': 'AsSaffiyah',
  'Best of Creation': 'AsSaffiyah',
};

export function getDistrict(museumName: string): string {
  return MUSEUM_DISTRICT[museumName] || 'Other';
}

export const CHANNEL_LABELS: Record<string, string> = {
  'B2C': 'HiHala Website/App',
  'B2B': 'B2B',
  'POS': 'POS',
  'Safiyyah POS': 'Safiyyah POS',
  'Standalone': 'Standalone',
  'Mobile': 'Mobile',
  'Viva': 'Viva',
  'IT': 'IT',
};

export function getChannelLabel(operatingAreaName: string): string {
  return CHANNEL_LABELS[operatingAreaName] || operatingAreaName;
}
