from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from core.models import EducationalLevel, Subject, Teacher

class Command(BaseCommand):
    help = 'Seeds the database with sample data'

    def handle(self, *args, **kwargs):
        # Create a teacher
        user, created = User.objects.get_or_create(username='teacher1', email='teacher1@example.com')
        if created:
            user.set_password('password123')
            user.save()
        
        teacher, _ = Teacher.objects.get_or_create(user=user, specialization='Mathematics')

        # Create Educational Levels
        l1, _ = EducationalLevel.objects.get_or_create(
            name_en='Primary School',
            name_ar='المرحلة الابتدائية',
            description='Grades 1-6'
        )
        l2, _ = EducationalLevel.objects.get_or_create(
            name_en='High School',
            name_ar='المرحلة الثانوية',
            description='Grades 10-12'
        )

        # Create Subjects
        Subject.objects.get_or_create(
            level=l1,
            teacher=teacher,
            name_en='Basic Math',
            name_ar='الرياضيات الأساسية',
            description_en='Learn basic addition, subtraction, and multiplication.',
            description_ar='تعلم الجمع والطرح والضرب الأساسي.',
            price=20.00
        )
        Subject.objects.get_or_create(
            level=l2,
            teacher=teacher,
            name_en='Physics',
            name_ar='الفيزياء',
            description_en='Advanced physics for high school students.',
            description_ar='فيزياء متقدمة لطلاب الثانوية العامة.',
            price=50.00
        )
        Subject.objects.get_or_create(
            level=l2,
            teacher=teacher,
            name_en='Chemistry',
            name_ar='الكيمياء',
            description_en='Explore the world of chemical reactions.',
            description_ar='استكشف عالم التفاعلات الكيميائية.',
            price=45.00
        )

        self.stdout.write(self.style.SUCCESS('Successfully seeded sample data'))
