/* ===== 搜索结果类型 ===== */
export interface SearchResult {
  id: string
  title: string
  description?: string
  cover?: string
  file_size?: string
  update_time?: string
  datetime?: string
  cloud_type: CloudType
  share_url?: string
  source?: string
  password?: string
  file_id?: string
  valid?: boolean
}

export type CloudType =
  | 'quark' | 'baidu' | 'aliyun' | '115'
  | 'tianyi' | '123pan' | 'uc' | 'xunlei'
  | 'pikpak' | 'magnet' | 'ed2k' | 'others'

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

export const CLOUD_COLORS: Record<CloudType, 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',
}

/**
 * 网盘图标映射 — 全部使用内联 SVG data URI，无需外部文件
/**
 * 网盘图标映射 — 使用仓库中的 PNG 图标文件
 * 图标存储在 public/icons/ 目录下，Vite 构建时自动打包
 */
/** 与 src/config/cloud-icons.ts 同步 */
export const CLOUD_ICONS: Record<string, string> = {
  baidu:   '/icons/baidu.png',
  aliyun:  '/icons/aliyun.png',
  quark:   '/icons/quark.png',
  '115':   '/icons/115.png',
  tianyi:  '/icons/tianyi.png',
  '123pan': '/icons/123pan.png',
  uc:      '/icons/uc.png',
  xunlei:  '/icons/xunlei.png',
  pikpak:  '/icons/pikpak.png',
  magnet:  '/icons/magnet.png',
  ed2k:    '/icons/ed2k.png',
  others:  '/icons/others.png',
}

/* ===== 视频解析类型 ===== */
export interface VideoParseResult {
  title: string
  cover: string
  video_url: string
  author?: string
  platform: string
  description?: string
}

/* ===== 保存结果类型 ===== */
export interface SaveResult {
  success: boolean
  share_url: string
  share_pwd?: string
  expire_at?: string
  file_name: string
  file_size: string
  message?: string
}

/* ===== 排行榜类型 ===== */
export interface RankingItem {
  id: number
  title: string
  search_count: number
  cloud_type: CloudType
  cover?: string
}

/* ===== 推广类型 ===== */
export interface Promotion {
  id?: number
  title: string
  description: string
  image_url: string
  link_url: string
  position: 'home_banner' | 'search_top' | 'sidebar'
  sort_order: number
  active: boolean
  click_count?: number
  start_time?: string
  end_time?: string
}

/* ===== 网盘配置类型 ===== */
export interface CloudConfig {
  id?: number
  cloud_type: CloudType
  nickname?: string
  is_active: boolean
  cookie?: string
  cookie_preview?: string
  storage_used?: string
  storage_total?: string
  checkin_status?: 'none' | 'success' | 'failed' | 'pending' | 'skipped'
  last_checkin_at?: string
  checkin_message?: string
  consecutive_failures?: number
  last_used_at?: string
  total_saves?: number
  verification_status?: 'untested' | 'valid' | 'invalid'
  last_verified_at?: string
  promotion_account?: string
  is_transfer_enabled?: number
}

/* ===== API 响应类型 ===== */
export interface ApiResponse<T = any> {
  success: boolean
  data?: T
  message?: string
  error?: string
}

export interface SearchResponse {
  results: SearchResult[]
  total: number
  filtered: number
  channels?: ChannelGroup[]
  link_validation?: boolean
}

export interface ChannelGroup {
  cloud_type: string
  label: string
  color: string
  count: number
  items: any[]
  newestTime?: string
}

export interface StatsData {
  todaySearches: number
  todaySaves: number
  monthSearches: number
  monthSaves: number
  totalSearches: number
  totalSaves: number
  hotKeywords: { keyword: string; count: number }[]
  trendTrend: { date: string; searches: number; saves: number; searchDelta: number; saveDelta: number }[]
  cloudUsage: { cloudType: string; nickname: string; storageUsed: string; storageTotal: string; isActive: boolean }[]
  topIps: { ip: string; ip_location: string | null; count: number }[]
  provinceRankings: { province: string; count: number }[]
}

/* ===== 意图识别结果 ===== */
export type IntentType = 'SEARCH' | 'VIDEO_PARSE' | 'CLOUD_SAVE'

export interface QueryResponse {
  intent: IntentType
  results: SearchResult[] | VideoParseResult[]
  channels?: ChannelGroup[]
  total: number
  filtered?: number
  platform?: string
  link_validation?: boolean
}
