from django.core.management.base import BaseCommand
from core.models import Course, Module, Lesson

class Command(BaseCommand):
    help = 'Seeds initial Python course data'

    def handle(self, *args, **kwargs):
        # Python Fundamentals
        course1, created = Course.objects.get_or_create(
            title='Python Fundamentals',
            defaults={'description': 'A comprehensive guide to Python for absolute beginners. High-contrast learning.'}
        )

        m1, _ = Module.objects.get_or_create(course=course1, title='Getting Started', order=1)
        m2, _ = Module.objects.get_or_create(course=course1, title='Control Flow', order=2)
        m3, _ = Module.objects.get_or_create(course=course1, title='Data Structures', order=3)

        Lesson.objects.get_or_create(
            module=m1, title='Installation & Setup', 
            defaults={'content': 'In this lesson, we will install Python 3.11 and set up a minimalist IDE like VS Code or just use a terminal.', 'order': 1}
        )
        Lesson.objects.get_or_create(
            module=m1, title='Variables & Data Types', 
            defaults={'content': 'Python is dynamically typed. Learn about integers, strings, and booleans.', 'order': 2}
        )
        Lesson.objects.get_or_create(
            module=m2, title='If-Else Statements', 
            defaults={'content': 'Logic flows. If this then that. Else something else.', 'order': 1}
        )
        Lesson.objects.get_or_create(
            module=m3, title='Lists & Tuples', 
            defaults={'content': 'Learn how to store multiple items in a single variable using lists and immutable tuples.', 'order': 1}
        )
        Lesson.objects.get_or_create(
            module=m3, title='Dictionaries & Sets', 
            defaults={'content': 'Master key-value pairs and unique collections of items.', 'order': 2}
        )

        # Advanced Python
        course2, created = Course.objects.get_or_create(
            title='Advanced Python',
            defaults={'description': 'Take your Python skills to the next level with complex architectures and patterns.'}
        )

        am1, _ = Module.objects.get_or_create(course=course2, title='Object Oriented Programming', order=1)
        am2, _ = Module.objects.get_or_create(course=course2, title='Decorators & Generators', order=2)

        Lesson.objects.get_or_create(
            module=am1, title='Classes and Objects', 
            defaults={'content': 'Understand the core concepts of OOP: how to define classes and instantiate objects.', 'order': 1}
        )
        Lesson.objects.get_or_create(
            module=am1, title='Inheritance', 
            defaults={'content': 'Learn how to create subclasses that inherit attributes and methods from a parent class.', 'order': 2}
        )
        Lesson.objects.get_or_create(
            module=am2, title='Function Decorators', 
            defaults={'content': 'Enhance your functions without modifying their source code using decorators.', 'order': 1}
        )

        self.stdout.write(self.style.SUCCESS('Successfully seeded extended Python Lern data'))