// API 统一导出文件
export * from './types'
export * from './request'

// 导出所有API模块
export { default as AuthApi } from './modules/auth'
export { default as CourseApi } from './modules/course'
export { default as CommentApi } from './modules/comment'
export { default as FavoriteApi } from './modules/favorite'
export { default as OrderApi } from './modules/order'
export { default as UploadApi } from './modules/upload'
export { default as StatisticsApi } from './modules/statistics'

// API 基础配置
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000/api'

// API 端点配置
export const API_ENDPOINTS = {
  // 认证相关
  AUTH: {
    LOGIN: '/auth/login',
    REGISTER: '/auth/register',
    LOGOUT: '/auth/logout',
    REFRESH: '/auth/refresh',
    ME: '/auth/me',
    PROFILE: '/auth/profile',
    CHANGE_PASSWORD: '/auth/change-password',
    FORGOT_PASSWORD: '/auth/forgot-password',
    RESET_PASSWORD: '/auth/reset-password',
    VERIFY_EMAIL: '/auth/verify-email',
    VERIFY_PHONE: '/auth/verify-phone',
    UPLOAD_AVATAR: '/auth/upload-avatar',
  },
  
  // 课程相关
  COURSES: {
    LIST: '/courses',
    SEARCH: '/courses/search',
    POPULAR: '/courses/popular',
    LATEST: '/courses/latest',
    RECOMMENDED: '/courses/recommended',
    DETAIL: '/courses/:id',
    CHAPTERS: '/courses/:id/chapters',
    LESSONS: '/courses/:id/lessons',
    ENROLL: '/courses/:id/enroll',
    PROGRESS: '/courses/:id/progress',
    PREVIEW: '/courses/:id/preview',
    STATS: '/courses/:id/stats',
    RELATED: '/courses/:id/related',
    ACCESS: '/courses/:id/access',
  },
  
  // 分类相关
  CATEGORIES: {
    LIST: '/categories',
    COURSES: '/categories/:id/courses',
  },
  
  // 章节课时相关
  CHAPTERS: {
    DETAIL: '/chapters/:id',
  },
  
  LESSONS: {
    DETAIL: '/lessons/:id',
    RESOURCES: '/lessons/:id/resources',
    COMPLETE: '/lessons/:id/complete',
  },
  
  // 讲师相关
  INSTRUCTORS: {
    DETAIL: '/instructors/:id',
    COURSES: '/instructors/:id/courses',
    FOLLOW: '/instructors/:id/follow',
  },
  
  // 测验相关
  QUIZZES: {
    LIST: '/courses/:id/quizzes',
    DETAIL: '/quizzes/:id',
    SUBMIT: '/quizzes/:id/submit',
    RESULTS: '/quizzes/:id/results',
  },
  
  // 评论相关
  COMMENTS: {
    COURSE: '/courses/:id/comments',
    LESSON: '/lessons/:id/comments',
    DETAIL: '/comments/:id',
    REPLIES: '/comments/:id/replies',
    LIKE: '/comments/:id/like',
    DISLIKE: '/comments/:id/dislike',
    HELPFUL: '/comments/:id/helpful',
    REPORT: '/comments/:id/report',
    MY_COMMENTS: '/my-comments',
    STATS: '/comments/stats',
  },
  
  // 收藏相关
  FAVORITES: {
    LIST: '/favorites',
    ADD: '/favorites',
    REMOVE: '/favorites/:id',
    CHECK: '/favorites/check/:id',
    BATCH: '/favorites/batch',
    STATS: '/favorites/stats',
    EXPORT: '/favorites/export',
    IMPORT: '/favorites/import',
    FOLDERS: '/favorite-folders',
  },
  
  // 订单相关
  ORDERS: {
    LIST: '/orders',
    CREATE: '/orders',
    DETAIL: '/orders/:id',
    BY_NO: '/orders/no/:orderNo',
    CANCEL: '/orders/:id/cancel',
    CONFIRM_PAYMENT: '/orders/:id/confirm-payment',
    REFUND: '/orders/:id/refund',
    INVOICE: '/orders/:id/invoice',
    STATS: '/orders/stats',
    CALCULATE: '/orders/calculate',
  },
  
  // 支付相关
  PAYMENT: {
    METHODS: '/payment-methods',
    STATUS: '/orders/:id/payment-status',
    RETRY: '/orders/:id/retry-payment',
  },
  
  // 优惠券相关
  COUPONS: {
    VALIDATE: '/coupons/validate',
    AVAILABLE: '/coupons/available',
  },
  
  // 退款相关
  REFUNDS: {
    LIST: '/refunds',
    DETAIL: '/refunds/:id',
  },
  
  // 上传相关
  UPLOAD: {
    FILE: '/upload/:type',
    AVATAR: '/upload/avatar',
    COURSE_THUMBNAIL: '/upload/course-thumbnail',
    COURSE_VIDEO: '/upload/course-video',
    COURSE_RESOURCE: '/upload/course-resource',
    MULTIPLE: '/upload/multiple/:type',
    CONFIG: '/upload/config',
    TOKEN: '/upload/token/:type',
    COMPRESS: '/upload/compress-image',
    THUMBNAIL: '/upload/generate-thumbnail',
    HISTORY: '/upload/history',
  },
  
  // 统计相关
  STATISTICS: {
    PLATFORM: '/statistics/platform',
    USER_LEARNING: '/statistics/user-learning',
    COURSE: '/statistics/course/:id',
    INSTRUCTOR: '/statistics/instructor/:id',
    LEARNING_PROGRESS: '/statistics/learning-progress',
    REVENUE: '/statistics/revenue',
    USER_BEHAVIOR: '/statistics/user-behavior',
    SEARCH: '/statistics/search',
    CONTENT: '/statistics/content',
    COMMENTS: '/statistics/comments',
    EXPORT: '/statistics/export/:type',
  },
  
  // 学习进度相关
  LEARNING: {
    PROGRESS: '/learning-progress',
    MY_COURSES: '/my-courses',
  },
  
  // 资源相关
  RESOURCES: {
    DOWNLOAD: '/resources/:id/download',
  },
}

// 请求配置
export const REQUEST_CONFIG = {
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json',
  },
}

// HTTP状态码
export const HTTP_STATUS = {
  OK: 200,
  CREATED: 201,
  NO_CONTENT: 204,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  VALIDATION_ERROR: 422,
  TOO_MANY_REQUESTS: 429,
  INTERNAL_ERROR: 500,
  BAD_GATEWAY: 502,
  SERVICE_UNAVAILABLE: 503,
  GATEWAY_TIMEOUT: 504,
}

// 业务状态码
export const BUSINESS_CODE = {
  SUCCESS: 0,
  FAILED: 1,
  INVALID_PARAMS: 1001,
  UNAUTHORIZED: 1002,
  FORBIDDEN: 1003,
  NOT_FOUND: 1004,
  ALREADY_EXISTS: 1005,
  OPERATION_FAILED: 1006,
  VALIDATION_FAILED: 1007,
  RATE_LIMITED: 1008,
  MAINTENANCE: 1009,
}

// 常用的API响应消息
export const API_MESSAGES = {
  SUCCESS: '操作成功',
  FAILED: '操作失败',
  INVALID_PARAMS: '参数错误',
  UNAUTHORIZED: '未授权访问',
  FORBIDDEN: '禁止访问',
  NOT_FOUND: '资源不存在',
  ALREADY_EXISTS: '资源已存在',
  NETWORK_ERROR: '网络错误',
  SERVER_ERROR: '服务器错误',
  TIMEOUT: '请求超时',
  UNKNOWN_ERROR: '未知错误',
}

// 分页默认配置
export const PAGINATION_CONFIG = {
  DEFAULT_PAGE: 1,
  DEFAULT_PAGE_SIZE: 20,
  MAX_PAGE_SIZE: 100,
}

// 文件上传配置
export const UPLOAD_CONFIG = {
  MAX_FILE_SIZE: 100 * 1024 * 1024, // 100MB
  ALLOWED_IMAGE_TYPES: ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
  ALLOWED_VIDEO_TYPES: ['video/mp4', 'video/avi', 'video/mov', 'video/wmv'],
  ALLOWED_DOCUMENT_TYPES: ['application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
  ALLOWED_AUDIO_TYPES: ['audio/mp3', 'audio/wav', 'audio/ogg'],
}

// 缓存配置
export const CACHE_CONFIG = {
  DEFAULT_TTL: 5 * 60 * 1000, // 5分钟
  USER_INFO_TTL: 30 * 60 * 1000, // 30分钟
  COURSE_LIST_TTL: 10 * 60 * 1000, // 10分钟
  STATIC_DATA_TTL: 60 * 60 * 1000, // 1小时
}
