from django.core.management.base import BaseCommand
from courses.models import Course, Semester, Subject

class Command(BaseCommand):
    help = 'Seed all semesters and subjects for B.Tech (Hons) CSE course.'

    def handle(self, *args, **options):
        course = Course.objects.get(slug="btech-hons-cse")
        roman_to_num = {
            "I": 1, "II": 2, "III": 3, "IV": 4,
            "V": 5, "VI": 6, "VII": 7, "VIII": 8
        }
        subjects_data = [
            ("24BAS101T", "Engineering Mathematics - I", "I", 4),
            ("24BAS102P", "Engineering Physics Lab", "I", 1),
            ("24BAS102T", "Engineering Physics", "I", 3),
            ("24BCS101P", "Computational Thinking and Programming in C Lab", "I", 1),
            ("24BCS101T", "Computational Thinking and Programming in C", "I", 3),
            ("24BME101P", "Concepts of Mechanical Engineering Lab", "I", 1),
            ("24BME101T", "Concepts of Mechanical Engineering", "I", 3),
            ("24SEC002P", "Advance Digital Marketing Lab", "I", 1),
            ("24SEC002T", "Advance Digital Marketing", "I", 3),
            ("24AEC001T", "Soft Skills and Verbal Communication-I", "I", 3),
            ("24BAS201T", "Engineering Mathematics - II", "II", 4),
            ("24BCE101T", "Energy & Environmental Engineering", "II", 3),
            ("24BCE101P", "Energy & Environmental Engineering Lab", "II", 1),
            ("24BCS201P", "Data Structures Lab", "II", 1),
            ("24BCS201T", "Data Structures", "II", 4),
            ("24BEC101P", "Principles of Electrical & Electronics Engineering Lab", "II", 1),
            ("24BEC101T", "Principles of Electrical & Electronics Engineering", "II", 3),
            ("24SEC009P", "Advance IT Tools for Office Automation Lab", "II", 1),
            ("24SEC009T", "Advance IT Tools for Office Automation", "II", 3),
            ("24SEC003T", "Quantitative, Aptitude and Logical Reasoning-I", "II", 2),
            ("24SYN101P", "Health Wellness (Sports/Yoga/NCC)", "II", 2),
            ("24BAS301T", "Discrete Mathematics", "III", 4),
            ("24BCS301P", "Operating System Lab", "III", 1),
            ("24BCS301T", "Operating System", "III", 3),
            ("24BCS302P", "Object Oriented Programming using Java Lab", "III", 1),
            ("24BCS302T", "Object Oriented Programming using Java", "III", 4),
            ("24BCS303T", "Introduction to Artificial Intelligence", "III", 3),
            ("24BCS304P", "Python Programming Lab", "III", 1),
            ("24BCS304T", "Python Programming", "III", 3),
            ("24AEC002T", "Soft Skills and Verbal Communication-II", "III", 3),
            ("24SIP001P", "Summer Internship-I", "III", 2),
            ("24BCS401P", "Design and Analysis of Algorithms Lab", "IV", 1),
            ("24BCS401T", "Design and Analysis of Algorithms", "IV", 4),
            ("24BCS402T", "Theory of Automata and Formal Languages", "IV", 4),
            ("24BCS403T", "Software Engineering", "IV", 3),
            ("24BCS404P", "Machine Learning with Python Lab", "IV", 1),
            ("24BCS404T", "Machine Learning with Python", "IV", 3),
            ("24BCS405P", "Drone Application, Components and Assembly Lab", "IV", 1),
            ("24BCS405T", "Drone Application, Components and Assembly", "IV", 3),
            ("24BCS406P", "Web Technologies (HTML/CSS/PHP) Lab", "IV", 1),
            ("24BCS406T", "Web Technologies (HTML/CSS/PHP)", "IV", 4),
            ("24SEC004T", "Quantitative, Aptitude and Logical Reasoning-II", "IV", 2),
            ("24BCS501P", "Database Management System Lab", "V", 1),
            ("24BCS501T", "Database Management System", "V", 4),
            ("24BCS502P", "Computer Networks Lab", "V", 1),
            ("24BCS502T", "Computer Networks", "V", 4),
            ("24BCS503T", "Computer Organization and Architecture", "V", 3),
            ("24BCS504P", "Compiler Design Lab", "V", 1),
            ("24BCS504T", "Compiler Design", "V", 4),
            ("24ECSXXXT", "Discipline Elective-I", "V", 3),
            ("24ECS508T", "Front End web UI Framework and Tools: Bootstrap", "V", 0),
            ("24AEC003T", "Soft Skills and Verbal Communication-III", "V", 3),
            ("24SIP002P", "Summer Internship-II", "V", 2),
            ("24BCS601T", "Cloud Computing", "VI", 4),
            ("24BCS602P", "Data Mining & Warehousing Lab", "VI", 1),
            ("24BCS602T", "Data Mining & Warehousing", "VI", 4),
            ("24BCS603P", "Joy of Deep Learning Lab", "VI", 1),
            ("24BCS603T", "Joy of Deep Learning", "VI", 4),
            ("24BCS604T", "Fundamental of Cyber Security", "VI", 3),
            ("24ECSXXXT", "Discipline Elective-II", "VI", 3),
            ("24ECS608T", "Introduction to Angular JS and Mongo DB", "VI", 0),
            ("24ECSXXXT", "Discipline Elective-III", "VI", 3),
            ("24SEC005T", "Quantitative, Aptitude and Logical Reasoning-III", "VI", 2),
            ("24BCS701P", "Cryptography and Network Security Lab", "VII", 1),
            ("24BCS701T", "Cryptography and Network Security", "VII", 4),
            ("24BCS702P", "Big Data Analytics Lab", "VII", 1),
            ("24BCS702T", "Big Data Analytics", "VII", 3),
            ("24ECSXXXT", "Discipline Elective-IV", "VII", 3),
            ("24ECSXXXT", "Discipline Elective-V", "VII", 3),
            ("24OECXXXT", "Open Elective", "VII", 3),
            ("24MDC001T", "Innovation and Entrepreneurship", "VII", 3),
            ("24BCS709P", "Minor Project", "VII", 2),
            ("24SIP003P", "Summer Internship-III", "VII", 2),
            ("24BCS801P", "Major Project", "VIII", 12),
            ("24VAC003P", "MOOC/Swayam Online Course of Min 08 Weeks (As decided by department)/Value Added Course run by University - I", "VIII", 2),
            ("24VAC004P", "MOOC/Swayam Online Course of Min 08 Weeks (As decided by department)/Value Added Course run by University - II", "VIII", 2),
            ("24SEC010P", "Patent/Research Publication/Startup", "VIII", 2),
        ]
        for sem_roman in ["I", "II", "III", "IV", "V", "VI", "VII", "VIII"]:
            sem_number = roman_to_num[sem_roman]
            semester, _ = Semester.objects.get_or_create(course=course, name=sem_roman, number=sem_number)
            for code, name, sem, credits in subjects_data:
                if sem == sem_roman:
                    Subject.objects.get_or_create(
                        semester=semester,
                        code=code,
                        name=name,
                        credits=credits,
                        description=""
                    )
        self.stdout.write(self.style.SUCCESS('All semesters and subjects have been added for btech-hons-cse.'))
