import 'package:flutter/material.dart';
import '../models/listening_exercise_model.dart';

/// 听力训练静态数据
class ListeningStaticData {
  /// 获取所有听力练习
  static List<ListeningExercise> getAllExercises() {
    return [
      // 日常对话类
      ListeningExercise(
        id: 'daily_001',
        title: 'At the Restaurant',
        description: '在餐厅点餐的日常对话练习',
        type: ListeningExerciseType.conversation,
        difficulty: ListeningDifficulty.beginner,
        audioUrl: 'assets/audio/daily_restaurant.mp3',
        duration: 180,
        transcript: '''
A: Good evening! Welcome to our restaurant. How many people are in your party?
B: Good evening! There are four of us.
A: Perfect! Right this way, please. Here's your table.
B: Thank you. Could we see the menu, please?
A: Of course! Here are your menus. Can I start you off with something to drink?
B: I'll have a glass of water, please.
A: And for the others?
C: I'd like a coffee, please.
D: Orange juice for me.
E: I'll have tea, thank you.
A: Excellent! I'll be right back with your drinks.
''',
        questions: [
          ListeningQuestion(
            id: 'q1',
            type: ListeningQuestionType.multipleChoice,
            question: 'How many people are in the party?',
            options: ['Two', 'Three', 'Four', 'Five'],
            correctAnswer: 'Four',
            explanation: '对话中明确提到"There are four of us"',
            timeStart: 5,
            timeEnd: 15,
            points: 10,
          ),
          ListeningQuestion(
            id: 'q2',
            type: ListeningQuestionType.multipleChoice,
            question: 'What does the first customer order to drink?',
            options: ['Coffee', 'Water', 'Orange juice', 'Tea'],
            correctAnswer: 'Water',
            explanation: '第一位顾客说"I\'ll have a glass of water, please"',
            timeStart: 45,
            timeEnd: 55,
            points: 10,
          ),
        ],
        tags: ['日常对话', '餐厅', '点餐'],
        thumbnailUrl: 'assets/images/restaurant.jpg',
        totalPoints: 20,
        passingScore: 0.7,
        creatorId: 'system',
        creatorName: 'AI英语学习',
        isPublic: true,
        playCount: 1250,
        rating: 4.5,
        reviewCount: 89,
        createdAt: DateTime.now().subtract(const Duration(days: 30)),
        updatedAt: DateTime.now().subtract(const Duration(days: 5)),
      ),

      ListeningExercise(
        id: 'daily_002',
        title: 'Shopping for Clothes',
        description: '购买衣服时的对话练习',
        type: ListeningExerciseType.dialogue,
        difficulty: ListeningDifficulty.elementary,
        audioUrl: 'assets/audio/shopping_clothes.mp3',
        duration: 240,
        transcript: '''
A: Can I help you find anything today?
B: Yes, I'm looking for a winter coat.
A: What size are you looking for?
B: I think I'm a medium, but I'm not sure.
A: Let me show you our selection. These are very popular this season.
B: I like this blue one. Can I try it on?
A: Of course! The fitting rooms are right over there.
B: Thank you. How much does this cost?
A: That one is \$89.99, but it's on sale for \$69.99.
B: That's a great price! I'll take it.
''',
        questions: [
          ListeningQuestion(
            id: 'q1',
            type: ListeningQuestionType.multipleChoice,
            question: 'What is the customer looking for?',
            options: ['Summer dress', 'Winter coat', 'Spring jacket', 'Fall sweater'],
            correctAnswer: 'Winter coat',
            explanation: '顾客说"I\'m looking for a winter coat"',
            timeStart: 8,
            timeEnd: 18,
            points: 10,
          ),
          ListeningQuestion(
            id: 'q2',
            type: ListeningQuestionType.fillBlank,
            question: 'The coat costs _____ but it\'s on sale for _____.',
            options: ['\$89.99', '\$69.99'],
            correctAnswer: '\$89.99, \$69.99',
            explanation: '店员说原价\$89.99，现在特价\$69.99',
            timeStart: 55,
            timeEnd: 65,
            points: 15,
          ),
        ],
        tags: ['购物', '衣服', '价格'],
        thumbnailUrl: 'assets/images/shopping.jpg',
        totalPoints: 25,
        passingScore: 0.7,
        creatorId: 'system',
        creatorName: 'AI英语学习',
        isPublic: true,
        playCount: 980,
        rating: 4.3,
        reviewCount: 67,
        createdAt: DateTime.now().subtract(const Duration(days: 25)),
        updatedAt: DateTime.now().subtract(const Duration(days: 3)),
      ),

      // 新闻播报类
      ListeningExercise(
        id: 'news_001',
        title: 'Technology News Update',
        description: 'BBC科技新闻播报练习',
        type: ListeningExerciseType.news,
        difficulty: ListeningDifficulty.intermediate,
        audioUrl: 'assets/audio/tech_news.mp3',
        duration: 300,
        transcript: '''
Good morning, this is BBC Technology News. Today's top story: 
Apple has announced its latest iPhone model, featuring advanced AI capabilities and improved battery life. The new device, expected to launch next month, includes a revolutionary camera system that can automatically adjust settings based on lighting conditions.

In other tech news, researchers at MIT have developed a new type of solar panel that is 40% more efficient than current models. This breakthrough could significantly reduce the cost of renewable energy and help combat climate change.

Finally, the European Union has announced new regulations for artificial intelligence, requiring companies to ensure their AI systems are transparent and accountable. The regulations will take effect next year and could impact major tech companies worldwide.

That's all for today's technology update. I'm Sarah Johnson, BBC News.
''',
        questions: [
          ListeningQuestion(
            id: 'q1',
            type: ListeningQuestionType.multipleChoice,
            question: 'What is the main feature of Apple\'s new iPhone?',
            options: ['Longer battery life', 'Advanced AI capabilities', 'Better camera', 'All of the above'],
            correctAnswer: 'All of the above',
            explanation: '新闻中提到了AI功能、电池续航和相机系统的改进',
            timeStart: 15,
            timeEnd: 35,
            points: 15,
          ),
          ListeningQuestion(
            id: 'q2',
            type: ListeningQuestionType.multipleChoice,
            question: 'How much more efficient are the new solar panels?',
            options: ['30%', '40%', '50%', '60%'],
            correctAnswer: '40%',
            explanation: '新闻中明确提到"40% more efficient"',
            timeStart: 60,
            timeEnd: 80,
            points: 10,
          ),
          ListeningQuestion(
            id: 'q3',
            type: ListeningQuestionType.trueFalse,
            question: 'The EU AI regulations will take effect immediately.',
            options: ['True', 'False'],
            correctAnswer: 'False',
            explanation: '新闻中说"will take effect next year"，不是立即生效',
            timeStart: 120,
            timeEnd: 140,
            points: 10,
          ),
        ],
        tags: ['新闻', '科技', 'BBC'],
        thumbnailUrl: 'assets/images/tech_news.jpg',
        totalPoints: 35,
        passingScore: 0.75,
        creatorId: 'system',
        creatorName: 'AI英语学习',
        isPublic: true,
        playCount: 2100,
        rating: 4.7,
        reviewCount: 156,
        createdAt: DateTime.now().subtract(const Duration(days: 15)),
        updatedAt: DateTime.now().subtract(const Duration(days: 1)),
      ),

      // 商务英语类
      ListeningExercise(
        id: 'business_001',
        title: 'Business Meeting Discussion',
        description: '商务会议讨论练习',
        type: ListeningExerciseType.interview,
        difficulty: ListeningDifficulty.advanced,
        audioUrl: 'assets/audio/business_meeting.mp3',
        duration: 420,
        transcript: '''
Chair: Good morning, everyone. Let's begin today's quarterly review meeting. First, I'd like to hear from Sarah about our sales performance.

Sarah: Thank you, John. I'm pleased to report that our Q3 sales exceeded expectations by 15%. We've seen particularly strong growth in the Asian markets, with a 25% increase compared to last quarter.

Chair: That's excellent news. What factors contributed to this growth?

Sarah: Several factors played a role. Our new product line launched successfully, and our digital marketing campaign reached a wider audience than anticipated. Additionally, the partnership with local distributors in Asia has been very effective.

Chair: Great work, Sarah. Now, let's discuss our budget allocation for Q4. Michael, could you present the financial projections?

Michael: Certainly. Based on current trends, we're projecting a 12% revenue increase for Q4. However, we need to consider increased marketing costs and potential supply chain challenges.
''',
        questions: [
          ListeningQuestion(
            id: 'q1',
            type: ListeningQuestionType.multipleChoice,
            question: 'By how much did Q3 sales exceed expectations?',
            options: ['10%', '15%', '20%', '25%'],
            correctAnswer: '15%',
            explanation: 'Sarah说"exceeded expectations by 15%"',
            timeStart: 25,
            timeEnd: 35,
            points: 15,
          ),
          ListeningQuestion(
            id: 'q2',
            type: ListeningQuestionType.multipleChoice,
            question: 'What was the growth rate in Asian markets?',
            options: ['15%', '20%', '25%', '30%'],
            correctAnswer: '25%',
            explanation: 'Sarah提到亚洲市场"25% increase compared to last quarter"',
            timeStart: 40,
            timeEnd: 50,
            points: 15,
          ),
          ListeningQuestion(
            id: 'q3',
            type: ListeningQuestionType.shortAnswer,
            question: 'What are the three factors that contributed to the sales growth?',
            options: [],
            correctAnswer: 'New product line, digital marketing campaign, partnership with local distributors',
            explanation: 'Sarah提到了三个因素：新产品线、数字营销活动、与当地分销商的合作',
            timeStart: 70,
            timeEnd: 100,
            points: 20,
          ),
        ],
        tags: ['商务', '会议', '销售', '财务'],
        thumbnailUrl: 'assets/images/business_meeting.jpg',
        totalPoints: 50,
        passingScore: 0.8,
        creatorId: 'system',
        creatorName: 'AI英语学习',
        isPublic: true,
        playCount: 1560,
        rating: 4.6,
        reviewCount: 98,
        createdAt: DateTime.now().subtract(const Duration(days: 20)),
        updatedAt: DateTime.now().subtract(const Duration(days: 2)),
      ),

      // 学术讲座类
      ListeningExercise(
        id: 'academic_001',
        title: 'Climate Change Lecture',
        description: '气候变化学术讲座',
        type: ListeningExerciseType.lecture,
        difficulty: ListeningDifficulty.expert,
        audioUrl: 'assets/audio/climate_lecture.mp3',
        duration: 600,
        transcript: '''
Professor: Good afternoon, class. Today we'll be discussing the impact of climate change on global ecosystems. As you know, climate change refers to long-term shifts in global temperatures and weather patterns.

The primary driver of recent climate change is human activity, particularly the emission of greenhouse gases such as carbon dioxide, methane, and nitrous oxide. These gases trap heat in the Earth's atmosphere, leading to what we call the greenhouse effect.

The consequences of climate change are far-reaching. We're seeing rising sea levels, more frequent extreme weather events, and significant changes in precipitation patterns. These changes affect biodiversity, agriculture, and human settlements worldwide.

One of the most concerning aspects is the feedback loops that accelerate climate change. For example, as Arctic ice melts, less sunlight is reflected back to space, causing further warming. This is known as the albedo effect.

To address climate change, we need both mitigation and adaptation strategies. Mitigation involves reducing greenhouse gas emissions, while adaptation means adjusting to the changes that are already occurring.
''',
        questions: [
          ListeningQuestion(
            id: 'q1',
            type: ListeningQuestionType.multipleChoice,
            question: 'What is the primary driver of recent climate change?',
            options: ['Natural variations', 'Solar activity', 'Human activity', 'Volcanic eruptions'],
            correctAnswer: 'Human activity',
            explanation: '教授明确说"The primary driver of recent climate change is human activity"',
            timeStart: 30,
            timeEnd: 45,
            points: 15,
          ),
          ListeningQuestion(
            id: 'q2',
            type: ListeningQuestionType.multipleChoice,
            question: 'What is the albedo effect?',
            options: [
              'Greenhouse gas emissions',
              'Rising sea levels',
              'Reflection of sunlight by ice',
              'Extreme weather events'
            ],
            correctAnswer: 'Reflection of sunlight by ice',
            explanation: '教授解释了当北极冰融化时，反射回太空的阳光减少，这就是反照率效应',
            timeStart: 180,
            timeEnd: 200,
            points: 20,
          ),
          ListeningQuestion(
            id: 'q3',
            type: ListeningQuestionType.matching,
            question: 'Match the strategies with their definitions:',
            options: ['Mitigation', 'Adaptation'],
            correctAnswer: 'Mitigation: reducing greenhouse gas emissions; Adaptation: adjusting to changes',
            explanation: '教授解释了缓解是减少温室气体排放，适应是调整以应对已经发生的变化',
            timeStart: 240,
            timeEnd: 260,
            points: 25,
          ),
        ],
        tags: ['学术', '气候变化', '环境', '科学'],
        thumbnailUrl: 'assets/images/climate_lecture.jpg',
        totalPoints: 60,
        passingScore: 0.85,
        creatorId: 'system',
        creatorName: 'AI英语学习',
        isPublic: true,
        playCount: 890,
        rating: 4.8,
        reviewCount: 45,
        createdAt: DateTime.now().subtract(const Duration(days: 10)),
        updatedAt: DateTime.now().subtract(const Duration(days: 1)),
      ),
    ];
  }

  /// 根据类型获取听力练习
  static List<ListeningExercise> getExercisesByType(ListeningExerciseType type) {
    return getAllExercises().where((exercise) => exercise.type == type).toList();
  }

  /// 根据难度获取听力练习
  static List<ListeningExercise> getExercisesByDifficulty(ListeningDifficulty difficulty) {
    return getAllExercises().where((exercise) => exercise.difficulty == difficulty).toList();
  }

  /// 获取推荐的听力练习
  static List<ListeningExercise> getRecommendedExercises() {
    final allExercises = getAllExercises();
    allExercises.sort((a, b) => b.rating.compareTo(a.rating));
    return allExercises.take(3).toList();
  }

  /// 获取听力材料分类
  static List<ListeningCategory> getCategories() {
    return [
      ListeningCategory(
        id: 'daily',
        name: '日常对话',
        description: '日常生活中的对话练习',
        icon: Icons.chat,
        exerciseCount: getExercisesByType(ListeningExerciseType.conversation).length +
                      getExercisesByType(ListeningExerciseType.dialogue).length,
        type: ListeningExerciseType.conversation,
      ),
      ListeningCategory(
        id: 'news',
        name: '新闻播报',
        description: '新闻广播和报道练习',
        icon: Icons.newspaper,
        exerciseCount: getExercisesByType(ListeningExerciseType.news).length,
        type: ListeningExerciseType.news,
      ),
      ListeningCategory(
        id: 'business',
        name: '商务英语',
        description: '商务场景对话练习',
        icon: Icons.business,
        exerciseCount: getExercisesByType(ListeningExerciseType.interview).length,
        type: ListeningExerciseType.interview,
      ),
      ListeningCategory(
        id: 'academic',
        name: '学术讲座',
        description: '学术讲座和演讲练习',
        icon: Icons.school,
        exerciseCount: getExercisesByType(ListeningExerciseType.lecture).length,
        type: ListeningExerciseType.lecture,
      ),
    ];
  }

  /// 获取用户统计数据（模拟数据）
  static ListeningStatistics getUserStatistics() {
    return ListeningStatistics(
      userId: 'user_001',
      totalExercises: 50,
      completedExercises: 25,
      totalQuestions: 150,
      correctAnswers: 128,
      averageScore: 85.3,
      totalTimeSpent: 7200, // 2小时
      totalPlayCount: 89,
      streakDays: 7, // 连续学习7天
      difficultyStats: {
        ListeningDifficulty.beginner: 8,
        ListeningDifficulty.elementary: 10,
        ListeningDifficulty.intermediate: 5,
        ListeningDifficulty.advanced: 2,
        ListeningDifficulty.expert: 0,
      },
      typeStats: {
        ListeningExerciseType.conversation: 12,
        ListeningExerciseType.dialogue: 6,
        ListeningExerciseType.news: 4,
        ListeningExerciseType.interview: 2,
        ListeningExerciseType.lecture: 1,
        ListeningExerciseType.story: 0,
      },
      lastUpdated: DateTime.now(),
    );
  }
}

/// 听力材料分类
class ListeningCategory {
  final String id;
  final String name;
  final String description;
  final IconData icon;
  final int exerciseCount;
  final ListeningExerciseType type;

  const ListeningCategory({
    required this.id,
    required this.name,
    required this.description,
    required this.icon,
    required this.exerciseCount,
    required this.type,
  });
}