const IPHONE_MAP: Record<string, string> = {
  'iPhone10,1': 'iPhone 8',
  'iPhone10,4': 'iPhone 8',
  'iPhone10,2': 'iPhone 8 Plus',
  'iPhone10,5': 'iPhone 8 Plus',
  'iPhone10,3': 'iPhone X',
  'iPhone10,6': 'iPhone X',
  'iPhone11,2': 'iPhone XS',
  'iPhone11,4': 'iPhone XS Max',
  'iPhone11,6': 'iPhone XS Max',
  'iPhone11,8': 'iPhone XR',
  'iPhone12,1': 'iPhone 11',
  'iPhone12,3': 'iPhone 11 Pro',
  'iPhone12,5': 'iPhone 11 Pro Max',
  'iPhone12,8': 'iPhone SE (2. Gen.)',
  'iPhone13,1': 'iPhone 12 mini',
  'iPhone13,2': 'iPhone 12',
  'iPhone13,3': 'iPhone 12 Pro',
  'iPhone13,4': 'iPhone 12 Pro Max',
  'iPhone14,2': 'iPhone 13 Pro',
  'iPhone14,3': 'iPhone 13 Pro Max',
  'iPhone14,4': 'iPhone 13 mini',
  'iPhone14,5': 'iPhone 13',
  'iPhone14,6': 'iPhone SE (3. Gen.)',
  'iPhone14,7': 'iPhone 14',
  'iPhone14,8': 'iPhone 14 Plus',
  'iPhone15,2': 'iPhone 14 Pro',
  'iPhone15,3': 'iPhone 14 Pro Max',
  'iPhone15,4': 'iPhone 15',
  'iPhone15,5': 'iPhone 15 Plus',
  'iPhone16,1': 'iPhone 15 Pro',
  'iPhone16,2': 'iPhone 15 Pro Max',
  'iPhone17,1': 'iPhone 16 Pro',
  'iPhone17,2': 'iPhone 16 Pro Max',
  'iPhone17,3': 'iPhone 16',
  'iPhone17,4': 'iPhone 16 Plus',
  'iPhone17,5': 'iPhone 16e',
  'iPhone18,1': 'iPhone 17 Pro',
  'iPhone18,2': 'iPhone 17 Pro Max',
  'iPhone18,3': 'iPhone 17',
  'iPhone18,4': 'iPhone Air',
};

const IPAD_MAP: Record<string, string> = {
  'iPad13,4': 'iPad Pro 11" (M1)',
  'iPad13,5': 'iPad Pro 11" (M1)',
  'iPad13,6': 'iPad Pro 11" (M1)',
  'iPad13,7': 'iPad Pro 11" (M1)',
  'iPad13,8': 'iPad Pro 12.9" (M1)',
  'iPad13,9': 'iPad Pro 12.9" (M1)',
  'iPad13,10': 'iPad Pro 12.9" (M1)',
  'iPad13,11': 'iPad Pro 12.9" (M1)',
  'iPad13,16': 'iPad Air (5. Gen.)',
  'iPad13,17': 'iPad Air (5. Gen.)',
  'iPad13,18': 'iPad (10. Gen.)',
  'iPad13,19': 'iPad (10. Gen.)',
  'iPad14,1': 'iPad mini (6. Gen.)',
  'iPad14,2': 'iPad mini (6. Gen.)',
  'iPad14,3': 'iPad Pro 11" (M2)',
  'iPad14,4': 'iPad Pro 11" (M2)',
  'iPad14,5': 'iPad Pro 12.9" (M2)',
  'iPad14,6': 'iPad Pro 12.9" (M2)',
  'iPad14,8': 'iPad Air 11" (M2)',
  'iPad14,9': 'iPad Air 11" (M2)',
  'iPad14,10': 'iPad Air 13" (M2)',
  'iPad14,11': 'iPad Air 13" (M2)',
  'iPad16,1': 'iPad mini (A17 Pro)',
  'iPad16,2': 'iPad mini (A17 Pro)',
  'iPad16,3': 'iPad Pro 11" (M4)',
  'iPad16,4': 'iPad Pro 11" (M4)',
  'iPad16,5': 'iPad Pro 13" (M4)',
  'iPad16,6': 'iPad Pro 13" (M4)',
};

export function decodeAppleModel(modelCode: string | null | undefined): string {
  if (!modelCode) return '';
  const trimmed = modelCode.trim();
  return IPHONE_MAP[trimmed] ?? IPAD_MAP[trimmed] ?? trimmed;
}
