from django.core.management.base import BaseCommand
from api.models import MatchReview

class Command(BaseCommand):
    help = '填充比赛回顾数据'

    def handle(self, *args, **options):
        self.stdout.write('开始填充比赛回顾数据...')
        
        # 示例数据
        reviews_data = [
            {
                'name': '阿森纳首回合3-0领先皇马，赖斯生涯代表作',
                'thumbnail_url': '/media/videos/arsenal_vs_real_madrid/thumb.jpg',
                'video_url': '/media/videos/arsenal_vs_real_madrid/video.mp4'
            },
            {
                'name': '曼城绝杀热刺，哈兰德梅开二度',
                'thumbnail_url': '/media/videos/man_city_vs_tottenham/thumb.jpg',
                'video_url': '/media/videos/man_city_vs_tottenham/video.mp4'
            },
            {
                'name': '利物浦逆转切尔西，萨拉赫绝杀',
                'thumbnail_url': '/media/videos/liverpool_vs_chelsea/thumb.jpg',
                'video_url': '/media/videos/liverpool_vs_chelsea/video.mp4'
            }
        ]
        
        for review_data in reviews_data:
            review, created = MatchReview.objects.get_or_create(
                name=review_data['name'],
                defaults={
                    'thumbnail_url': review_data['thumbnail_url'],
                    'video_url': review_data['video_url']
                }
            )
            if created:
                self.stdout.write(
                    self.style.SUCCESS(f'创建比赛回顾: {review.name}')
                )
            else:
                self.stdout.write(
                    f'比赛回顾已存在: {review.name}'
                )
        
        self.stdout.write(
            self.style.SUCCESS('比赛回顾数据填充完成!')
        )