import random
from django.core.management.base import BaseCommand
from apps.crm.models import Teacher, Project

class Command(BaseCommand):
    help = 'Populate database with mock data for In-service Degrees and Opening Ceremonies'

    def handle(self, *args, **kwargs):
        self.stdout.write('Starting to populate degree and ceremony mock data...')

        # 1. Create Professors (Teachers)
        self.stdout.write('Creating Professors...')
        teachers_data = [
            {'name': '钱教授', 'phone': '13800138005', 'bio': '商学院资深教授，博士生导师，主讲企业战略管理。'},
            {'name': '孙教授', 'phone': '13800138006', 'bio': '心理学系主任，专注组织行为学研究。'},
            {'name': '周老师', 'phone': '13800138007', 'bio': '教务处主任，负责典礼与活动策划。'},
        ]
        
        teachers = []
        for data in teachers_data:
            teacher, created = Teacher.objects.get_or_create(name=data['name'], defaults=data)
            if created:
                self.stdout.write(f'Created teacher: {teacher.name}')
            else:
                self.stdout.write(f'Teacher already exists: {teacher.name}')
            teachers.append(teacher)

        # 2. Create Projects
        self.stdout.write('Creating Projects...')
        projects_data = [
            # In-service Degrees (training)
            {
                'title': 'MBA工商管理硕士',
                'project_type': 'training',
                'teacher': teachers[0],
                'image': 'https://images.unsplash.com/photo-1454165804606-c3d57bc86b40',
                'detail': '培养具有全球视野、战略思维和卓越领导力的商业领袖。课程涵盖管理经济学、组织行为学、市场营销、财务管理等核心模块。',
                'rating': 4.9,
                'duration': '2年',
                'price': 168000.00,
                'students': 120
            },
            {
                'title': 'EMBA高级工商管理硕士',
                'project_type': 'training',
                'teacher': teachers[0],
                'image': 'https://images.unsplash.com/photo-1556761175-5973dc0f32e7',
                'detail': '专为企业高层管理者设计，通过实战案例教学，提升决策能力和领导艺术。',
                'rating': 5.0,
                'duration': '2年',
                'price': 298000.00,
                'students': 45
            },
            {
                'title': '应用心理学在职研究生',
                'project_type': 'training',
                'teacher': teachers[1],
                'image': 'https://images.unsplash.com/photo-1571260899304-425eee4c7efc',
                'detail': '结合心理学理论与实践，帮助学员掌握心理咨询、EAP服务及人力资源管理中的心理学应用。',
                'rating': 4.8,
                'duration': '1.5年',
                'price': 48000.00,
                'students': 80
            },
            # Opening Ceremonies & Forums (competition)
            {
                'title': '2025春季开学典礼',
                'project_type': 'competition',
                'teacher': teachers[2],
                'image': 'https://images.unsplash.com/photo-1523580494863-6f3031224c94',
                'detail': '欢迎2025级新同学加入大家庭，届时将有校长致辞、新生代表发言及入学宣誓环节。',
                'rating': 5.0,
                'duration': '半天',
                'price': 0.00,
                'students': 300
            },
            {
                'title': '2024创新创业高峰论坛',
                'project_type': 'competition',
                'teacher': teachers[0],
                'image': 'https://images.unsplash.com/photo-1475721027767-27a66263adeb',
                'detail': '汇聚行业精英，探讨数字化时代的商业创新机遇与挑战。',
                'rating': 4.9,
                'duration': '1天',
                'price': 1280.00,
                'students': 200
            },
            {
                'title': '2024秋季毕业典礼',
                'project_type': 'competition',
                'teacher': teachers[2],
                'image': 'https://images.unsplash.com/photo-1627556704290-2b1f5853ff78',
                'detail': '见证荣耀时刻，开启人生新篇章。',
                'rating': 5.0,
                'duration': '半天',
                'price': 0.00,
                'students': 150
            }
        ]
        
        for data in projects_data:
            proj, created = Project.objects.get_or_create(title=data['title'], defaults=data)
            if created:
                self.stdout.write(f'Created project: {proj.title}')
            else:
                self.stdout.write(f'Project already exists: {proj.title}')

        self.stdout.write(self.style.SUCCESS('Successfully populated degree and ceremony mock data!'))
