/**
 * Cloud type labels and colors
 * Shared between backend and frontend-facing routes
 */

/** Cloud domain → type regex mapping (single source of truth) */
export const CLOUD_DOMAIN_PATTERNS: Array<{ regex: RegExp; type: string }> = [
  { regex: /pan\.baidu\.com/i, type: 'baidu' },
  { regex: /pan\.quark\.cn/i, type: 'quark' },
  { regex: /aliyundrive\.com|alipan\.com/i, type: 'aliyun' },
  { regex: /115\.com|115cdn\.com/i, type: '115' },
  { regex: /cloud\.189\.cn/i, type: 'tianyi' },
  { regex: /123pan\.com|123684\.com|123912\.com/i, type: '123pan' },
  { regex: /drive\.uc\.cn/i, type: 'uc' },
  { regex: /pan\.xunlei\.com/i, type: 'xunlei' },
  { regex: /magnet:/i, type: 'magnet' },
];

/** Detect cloud type from a URL string */
export function detectCloudType(url: string | undefined | null): string {
  if (!url) return 'others';
  for (const { regex, type } of CLOUD_DOMAIN_PATTERNS) {
    if (regex.test(url)) return type;
  }
  return 'others';
}

export const CLOUD_LABELS: Record<string, string> = {
  quark: '夸克网盘',
  baidu: '百度网盘',
  aliyun: '阿里云盘',
  '115': '115网盘',
  tianyi: '天翼云盘',
  '123pan': '123云盘',
  uc: 'UC网盘',
  xunlei: '迅雷云盘',
  pikpak: 'PikPak',
  magnet: '磁力链接',
  ed2k: '电驴链接',
  others: '其他',
};

export const CLOUD_COLORS: Record<string, string> = {
  quark: '#07c160',
  baidu: '#4e6ef2',
  aliyun: '#ff6a00',
  '115': '#9b59b6',
  tianyi: '#00a1d6',
  '123pan': '#e74c3c',
  uc: '#f39c12',
  xunlei: '#2ecc71',
  pikpak: '#8e44ad',
  magnet: '#95a5a6',
  ed2k: '#7f8c8d',
  others: '#95a5a6',
};
