import 'vocabulary_book_model.dart';
import 'vocabulary_book_category.dart';

/// 词汇书工厂类，用于生成各种分类的词汇书数据
class VocabularyBookFactory {
  
  /// 获取推荐词汇书
  static List<VocabularyBook> getRecommendedBooks({int limit = 8}) {
    final allBooks = <VocabularyBook>[];
    
    // 添加学段基础词汇
    allBooks.addAll(getAcademicStageBooks().take(2));
    
    // 添加国内考试词汇
    allBooks.addAll(getDomesticTestBooks().take(2));
    
    // 添加国际考试词汇
    allBooks.addAll(getInternationalTestBooks().take(2));
    
    // 添加职业专业词汇
    allBooks.addAll(getProfessionalBooks().take(1));
    
    // 添加功能型词汇
    allBooks.addAll(getFunctionalBooks().take(1));
    
    return allBooks.take(limit).toList();
  }

  /// 获取学段基础词汇书
  static List<VocabularyBook> getAcademicStageBooks() {
    return [
      // 小学词汇
      VocabularyBook(
        id: 'primary_basic',
        name: '小学英语基础词汇',
        description: '小学阶段必备英语词汇，涵盖日常生活和学习场景',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.beginner,
        mainCategory: VocabularyBookMainCategory.academicStage,
        subCategory: 'primary',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/primary_vocab.jpg',
        totalWords: 800,
        tags: ['小学', '基础', '日常'],
        targetLevels: ['小学1-3年级', '小学4-6年级'],
        estimatedDays: 40,
        dailyWordCount: 20,
        downloadCount: 25000,
        rating: 4.9,
        reviewCount: 2500,
        createdAt: DateTime.now().subtract(const Duration(days: 500)),
        updatedAt: DateTime.now().subtract(const Duration(days: 10)),
      ),
      
      // 初中词汇
      VocabularyBook(
        id: 'middle_school_core',
        name: '初中英语核心词汇',
        description: '初中阶段核心词汇，为中考打下坚实基础',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.elementary,
        mainCategory: VocabularyBookMainCategory.academicStage,
        subCategory: 'middle_school',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/middle_vocab.jpg',
        totalWords: 1600,
        tags: ['初中', '中考', '核心'],
        targetLevels: ['初一', '初二', '初三'],
        estimatedDays: 60,
        dailyWordCount: 30,
        downloadCount: 35000,
        rating: 4.8,
        reviewCount: 3500,
        createdAt: DateTime.now().subtract(const Duration(days: 450)),
        updatedAt: DateTime.now().subtract(const Duration(days: 15)),
      ),
      
      // 高中词汇
      VocabularyBook(
        id: 'high_school_essential',
        name: '高中英语必备词汇',
        description: '高中阶段必备词汇，涵盖高考重点词汇',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.intermediate,
        mainCategory: VocabularyBookMainCategory.academicStage,
        subCategory: 'high_school',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/high_vocab.jpg',
        totalWords: 3500,
        tags: ['高中', '高考', '必备'],
        targetLevels: ['高一', '高二', '高三'],
        estimatedDays: 100,
        dailyWordCount: 35,
        downloadCount: 45000,
        rating: 4.7,
        reviewCount: 4500,
        createdAt: DateTime.now().subtract(const Duration(days: 400)),
        updatedAt: DateTime.now().subtract(const Duration(days: 20)),
      ),
      
      // 大学词汇
      VocabularyBook(
        id: 'college_advanced',
        name: '大学英语进阶词汇',
        description: '大学阶段进阶词汇，提升学术英语水平',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.advanced,
        mainCategory: VocabularyBookMainCategory.academicStage,
        subCategory: 'college',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/college_vocab.jpg',
        totalWords: 5000,
        tags: ['大学', '学术', '进阶'],
        targetLevels: ['大一', '大二', '大三', '大四'],
        estimatedDays: 120,
        dailyWordCount: 40,
        downloadCount: 30000,
        rating: 4.6,
        reviewCount: 3000,
        createdAt: DateTime.now().subtract(const Duration(days: 350)),
        updatedAt: DateTime.now().subtract(const Duration(days: 25)),
      ),
    ];
  }

  /// 获取国内考试词汇书
  static List<VocabularyBook> getDomesticTestBooks() {
    return [
      // 四级词汇
      VocabularyBook(
        id: 'cet4_core',
        name: '大学英语四级词汇',
        description: '四级考试核心词汇，系统化备考',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.intermediate,
        mainCategory: VocabularyBookMainCategory.domesticTest,
        subCategory: 'cet4',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/cet4_vocab.jpg',
        totalWords: 4000,
        tags: ['四级', '考试', '核心'],
        targetLevels: ['四级425+', '四级500+'],
        estimatedDays: 80,
        dailyWordCount: 50,
        downloadCount: 50000,
        rating: 4.8,
        reviewCount: 5000,
        createdAt: DateTime.now().subtract(const Duration(days: 300)),
        updatedAt: DateTime.now().subtract(const Duration(days: 5)),
      ),
      
      // 六级词汇
      VocabularyBook(
        id: 'cet6_advanced',
        name: '大学英语六级词汇',
        description: '六级考试高级词汇，突破高分',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.intermediate,
        mainCategory: VocabularyBookMainCategory.domesticTest,
        subCategory: 'cet6',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/cet6_vocab.jpg',
        totalWords: 2500,
        tags: ['六级', '高级', '突破'],
        targetLevels: ['六级425+', '六级500+'],
        estimatedDays: 60,
        dailyWordCount: 45,
        downloadCount: 40000,
        rating: 4.7,
        reviewCount: 4000,
        createdAt: DateTime.now().subtract(const Duration(days: 280)),
        updatedAt: DateTime.now().subtract(const Duration(days: 8)),
      ),
      
      // 考研词汇
      VocabularyBook(
        id: 'postgraduate_essential',
        name: '考研英语核心词汇',
        description: '考研英语必备词汇，全面覆盖考点',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.advanced,
        mainCategory: VocabularyBookMainCategory.domesticTest,
        subCategory: 'postgraduate',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/postgrad_vocab.jpg',
        totalWords: 5500,
        tags: ['考研', '核心', '全面'],
        targetLevels: ['考研英语一', '考研英语二'],
        estimatedDays: 120,
        dailyWordCount: 45,
        downloadCount: 60000,
        rating: 4.9,
        reviewCount: 6000,
        createdAt: DateTime.now().subtract(const Duration(days: 250)),
        updatedAt: DateTime.now().subtract(const Duration(days: 3)),
      ),
      
      // 专四词汇
      VocabularyBook(
        id: 'tem4_professional',
        name: '英语专业四级词汇',
        description: '专四考试专业词汇，英语专业必备',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.advanced,
        mainCategory: VocabularyBookMainCategory.domesticTest,
        subCategory: 'tem4',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/tem4_vocab.jpg',
        totalWords: 8000,
        tags: ['专四', '专业', '英语'],
        targetLevels: ['英语专业大二'],
        estimatedDays: 150,
        dailyWordCount: 55,
        downloadCount: 25000,
        rating: 4.6,
        reviewCount: 2500,
        createdAt: DateTime.now().subtract(const Duration(days: 200)),
        updatedAt: DateTime.now().subtract(const Duration(days: 12)),
      ),
    ];
  }

  /// 获取国际考试词汇书
  static List<VocabularyBook> getInternationalTestBooks() {
    return [
      // 托福词汇
      VocabularyBook(
        id: 'toefl_core',
        name: '托福核心词汇',
        description: '托福考试必备核心词汇，涵盖学术和日常用语',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.advanced,
        mainCategory: VocabularyBookMainCategory.internationalTest,
        subCategory: 'toefl',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/toefl_vocab.jpg',
        totalWords: 5000,
        tags: ['托福', '学术', '高级'],
        targetLevels: ['托福80+', '托福100+'],
        estimatedDays: 100,
        dailyWordCount: 50,
        downloadCount: 35000,
        rating: 4.8,
        reviewCount: 3500,
        createdAt: DateTime.now().subtract(const Duration(days: 365)),
        updatedAt: DateTime.now().subtract(const Duration(days: 30)),
      ),
      
      // 雅思词汇
      VocabularyBook(
        id: 'ielts_essential',
        name: '雅思核心词汇',
        description: '雅思考试核心词汇，按话题分类整理',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.intermediate,
        mainCategory: VocabularyBookMainCategory.internationalTest,
        subCategory: 'ielts',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/ielts_vocab.jpg',
        totalWords: 4000,
        tags: ['雅思', '分类', '中级'],
        targetLevels: ['雅思6.0', '雅思7.0'],
        estimatedDays: 80,
        dailyWordCount: 50,
        downloadCount: 42000,
        rating: 4.7,
        reviewCount: 4200,
        createdAt: DateTime.now().subtract(const Duration(days: 300)),
        updatedAt: DateTime.now().subtract(const Duration(days: 15)),
      ),
      
      // GRE词汇
      VocabularyBook(
        id: 'gre_advanced',
        name: 'GRE高级词汇',
        description: 'GRE考试高难度词汇，学术研究必备',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.expert,
        mainCategory: VocabularyBookMainCategory.internationalTest,
        subCategory: 'gre',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/gre_vocab.jpg',
        totalWords: 6000,
        tags: ['GRE', '高难度', '学术'],
        targetLevels: ['GRE 320+', 'GRE 330+'],
        estimatedDays: 150,
        dailyWordCount: 40,
        downloadCount: 20000,
        rating: 4.5,
        reviewCount: 2000,
        createdAt: DateTime.now().subtract(const Duration(days: 180)),
        updatedAt: DateTime.now().subtract(const Duration(days: 7)),
      ),
    ];
  }

  /// 获取职业专业词汇书
  static List<VocabularyBook> getProfessionalBooks() {
    return [
      // 商务英语
      VocabularyBook(
        id: 'business_english',
        name: '商务英语词汇',
        description: '商务场景专业词汇，职场必备',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.intermediate,
        mainCategory: VocabularyBookMainCategory.professional,
        subCategory: 'business',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/business_vocab.jpg',
        totalWords: 2000,
        tags: ['商务', '职场', '专业'],
        targetLevels: ['职场新人', '商务精英'],
        estimatedDays: 50,
        dailyWordCount: 40,
        downloadCount: 18000,
        rating: 4.6,
        reviewCount: 1800,
        createdAt: DateTime.now().subtract(const Duration(days: 120)),
        updatedAt: DateTime.now().subtract(const Duration(days: 5)),
      ),
      
      // IT技术词汇
      VocabularyBook(
        id: 'it_technical',
        name: 'IT技术词汇',
        description: '信息技术专业词汇，程序员必备',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.intermediate,
        mainCategory: VocabularyBookMainCategory.professional,
        subCategory: 'it',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/it_vocab.jpg',
        totalWords: 1500,
        tags: ['IT', '技术', '程序员'],
        targetLevels: ['初级程序员', '高级工程师'],
        estimatedDays: 40,
        dailyWordCount: 35,
        downloadCount: 15000,
        rating: 4.7,
        reviewCount: 1500,
        createdAt: DateTime.now().subtract(const Duration(days: 100)),
        updatedAt: DateTime.now().subtract(const Duration(days: 8)),
      ),
    ];
  }

  /// 获取功能型词汇书
  static List<VocabularyBook> getFunctionalBooks() {
    return [
      // 词根词缀
      VocabularyBook(
        id: 'roots_affixes',
        name: '词根词缀大全',
        description: '掌握词根词缀，快速扩展词汇量',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.intermediate,
        mainCategory: VocabularyBookMainCategory.functional,
        subCategory: 'roots_affixes',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/roots_vocab.jpg',
        totalWords: 800,
        tags: ['词根', '词缀', '技巧'],
        targetLevels: ['中级学习者', '高级学习者'],
        estimatedDays: 30,
        dailyWordCount: 25,
        downloadCount: 22000,
        rating: 4.8,
        reviewCount: 2200,
        createdAt: DateTime.now().subtract(const Duration(days: 90)),
        updatedAt: DateTime.now().subtract(const Duration(days: 3)),
      ),
      
      // 日常口语
      VocabularyBook(
        id: 'daily_speaking',
        name: '日常口语词汇',
        description: '日常交流必备词汇，提升口语表达',
        type: VocabularyBookType.system,
        difficulty: VocabularyBookDifficulty.elementary,
        mainCategory: VocabularyBookMainCategory.functional,
        subCategory: 'speaking',
        coverImageUrl: 'https://ai-public.mastergo.com/ai/img_res/speaking_vocab.jpg',
        totalWords: 1200,
        tags: ['口语', '日常', '交流'],
        targetLevels: ['初级', '中级'],
        estimatedDays: 35,
        dailyWordCount: 35,
        downloadCount: 28000,
        rating: 4.9,
        reviewCount: 2800,
        createdAt: DateTime.now().subtract(const Duration(days: 80)),
        updatedAt: DateTime.now().subtract(const Duration(days: 2)),
      ),
    ];
  }

  /// 根据主分类获取词汇书
  static List<VocabularyBook> getBooksByMainCategory(VocabularyBookMainCategory category) {
    switch (category) {
      case VocabularyBookMainCategory.academicStage:
        return getAcademicStageBooks();
      case VocabularyBookMainCategory.domesticTest:
        return getDomesticTestBooks();
      case VocabularyBookMainCategory.internationalTest:
        return getInternationalTestBooks();
      case VocabularyBookMainCategory.professional:
        return getProfessionalBooks();
      case VocabularyBookMainCategory.functional:
        return getFunctionalBooks();
    }
  }

  /// 根据子分类获取词汇书
  static List<VocabularyBook> getBooksBySubCategory(String subCategory) {
    final allBooks = <VocabularyBook>[];
    allBooks.addAll(getAcademicStageBooks());
    allBooks.addAll(getDomesticTestBooks());
    allBooks.addAll(getInternationalTestBooks());
    allBooks.addAll(getProfessionalBooks());
    allBooks.addAll(getFunctionalBooks());
    
    return allBooks.where((book) => book.subCategory == subCategory).toList();
  }

  /// 根据难度获取词汇书
  static List<VocabularyBook> getBooksByDifficulty(VocabularyBookDifficulty difficulty) {
    final allBooks = <VocabularyBook>[];
    allBooks.addAll(getAcademicStageBooks());
    allBooks.addAll(getDomesticTestBooks());
    allBooks.addAll(getInternationalTestBooks());
    allBooks.addAll(getProfessionalBooks());
    allBooks.addAll(getFunctionalBooks());
    
    return allBooks.where((book) => book.difficulty == difficulty).toList();
  }

  /// 搜索词汇书
  static List<VocabularyBook> searchBooks(String query) {
    final allBooks = <VocabularyBook>[];
    allBooks.addAll(getAcademicStageBooks());
    allBooks.addAll(getDomesticTestBooks());
    allBooks.addAll(getInternationalTestBooks());
    allBooks.addAll(getProfessionalBooks());
    allBooks.addAll(getFunctionalBooks());
    
    final lowerQuery = query.toLowerCase();
    return allBooks.where((book) {
      return book.name.toLowerCase().contains(lowerQuery) ||
             book.description?.toLowerCase().contains(lowerQuery) == true ||
             book.tags.any((tag) => tag.toLowerCase().contains(lowerQuery));
    }).toList();
  }
}