from django.core.management.base import BaseCommand
from courses.models import (
    Course, CourseEligibility, CourseFee, FeeDetail, HostelFee, Semester, Subject,
    CareerProspect, Recruiter, WhyJoin, CourseHighlight, CourseImage, Testimonial
)

class Command(BaseCommand):
    help = 'Seed B.Tech (Hons) CSE course and all related data.'

    def handle(self, *args, **options):
        course, created = Course.objects.get_or_create(
            slug="btech-hons-cse",
            defaults={
                "title": "B.Tech Computer Science and Engineering",
                "short_description": "B.Tech in CSE prepares individuals for rewarding careers in a rapidly evolving field, equipping them with the skills and knowledge needed to thrive in the digital age.",
                "overview": "B.Tech gives students solid ground in engineering and technology. CSE is at the forefront of innovation, driving advancements in machine learning, robotics, VR, and more. Students learn to think critically and creatively to solve complex problems.",
                "duration": "4 Years",
                "category": "Engineering",
                "banner_image": "",
            }
        )

        CourseEligibility.objects.update_or_create(
            course=course,
            defaults={
                "academic_qualification": "Passed 10+2 examination with Physics, Chemistry, and Mathematics as compulsory subjects with at least 60% marks from recognized board.",
                "minimum_marks": "60%",
                "entrance_exam": "As per university norms"
            }
        )

        fee, _ = CourseFee.objects.update_or_create(
            course=course,
            defaults={
                "domestic": "132000",
                "international": "Contact for details"
            }
        )
        FeeDetail.objects.update_or_create(
            course_fee=fee,
            fee_head="Tuition Fee",
            defaults={
                "first_year": "132000",
                "second_year": "115000",
                "third_year": "115000",
                "fourth_year": "115000",
                "is_one_time": False
            }
        )

        HostelFee.objects.update_or_create(
            course=course,
            defaults={
                "fee_per_year": "60000",
                "ac_room_additional": "10000",
                "security_deposit": "5000",
                "notes": "Includes mess and laundry"
            }
        )

        semesters_subjects = {
            "I": [
                ("24BAS101T", "Engineering Mathematics - I", 4),
                ("24BAS102P", "Engineering Physics Lab", 1),
                ("24BAS102T", "Engineering Physics", 3),
                ("24BCS101P", "Computational Thinking and Programming in C Lab", 1),
                ("24BCS101T", "Computational Thinking and Programming in C", 3),
                ("24BME101P", "Concepts of Mechanical Engineering Lab", 1),
                ("24BME101T", "Concepts of Mechanical Engineering", 3),
                ("24SEC002P", "Advance Digital Marketing Lab", 1),
                ("24SEC002T", "Advance Digital Marketing", 3),
                ("24AEC001T", "Soft Skills and Verbal Communication-I", 3),
            ],
            "II": [
                ("24BAS201T", "Engineering Mathematics - II", 4),
                ("24BCE101T", "Energy & Environmental Engineering", 3),
                ("24BCE101P", "Energy & Environmental Engineering Lab", 1),
                ("24BCS201P", "Data Structures Lab", 1),
                ("24BCS201T", "Data Structures", 4),
                ("24BEC101P", "Principles of Electrical & Electronics Engineering Lab", 1),
                ("24BEC101T", "Principles of Electrical & Electronics Engineering", 3),
                ("24SEC009P", "Advance IT Tools for Office Automation Lab", 1),
                ("24SEC009T", "Advance IT Tools for Office Automation", 3),
                ("24SEC003T", "Quantitative, Aptitude and Logical Reasoning-I", 2),
                ("24SYN101P", "Health Wellness (Sports/Yoga/NCC)", 2),
            ],
            "III": [
                ("24BAS301T", "Discrete Mathematics", 4),
                ("24BCS301P", "Operating System Lab", 1),
                ("24BCS301T", "Operating System", 3),
                ("24BCS302P", "Object Oriented Programming using Java Lab", 1),
                ("24BCS302T", "Object Oriented Programming using Java", 4),
                ("24BCS303T", "Introduction to Artificial Intelligence", 3),
                ("24BCS304P", "Python Programming Lab", 1),
                ("24BCS304T", "Python Programming", 3),
                ("24AEC002T", "Soft Skills and Verbal Communication-II", 3),
                ("24SIP001P", "Summer Internship-I", 2),
            ],
            "IV": [
                ("24BCS401P", "Design and Analysis of Algorithms Lab", 1),
                ("24BCS401T", "Design and Analysis of Algorithms", 4),
                ("24BCS402T", "Theory of Automata and Formal Languages", 4),
                ("24BCS403T", "Software Engineering", 3),
                ("24BCS404P", "Machine Learning with Python Lab", 1),
                ("24BCS404T", "Machine Learning with Python", 3),
                ("24BCS405P", "Drone Application, Components and Assembly Lab", 1),
                ("24BCS405T", "Drone Application, Components and Assembly", 3),
                ("24BCS406P", "Web Technologies (HTML/CSS/PHP) Lab", 1),
                ("24BCS406T", "Web Technologies (HTML/CSS/PHP)", 4),
                ("24SEC004T", "Quantitative, Aptitude and Logical Reasoning-II", 2),
            ],
            # Add V, VI, VII, VIII similarly...
        }
        for idx, (sem_name, subjects) in enumerate(semesters_subjects.items(), start=1):
            semester, _ = Semester.objects.get_or_create(course=course, name=sem_name, number=idx)
            for code, name, credits in subjects:
                Subject.objects.get_or_create(
                    semester=semester,
                    code=code,
                    name=name,
                    credits=credits,
                    description=""
                )

        career_titles = [
            "Web Developer", "Database Administrator", "Data Analyst", "Information Security Analyst",
            "Network Architect", "Computer hardware engineer", "Artificial intelligence", "Network Engineer",
            "Game Developer", "IT support", "Cybersecurity", "Project Manager", "Entrepreneurship",
            "Software Developer", "Software Engineer", "System Manager", "Cloud Engineer", "MBA",
            "Web designer", "Engineering", "Business Analyst"
        ]
        for title in career_titles:
            CareerProspect.objects.get_or_create(course=course, title=title, defaults={
                "salary_range": "4-12 LPA",
                "description": f"Career in {title} after B.Tech CSE."
            })

        Recruiter.objects.get_or_create(course=course, name="Appsquadz Software Pvt. Ltd", logo="")
        Recruiter.objects.get_or_create(course=course, name="Igxact Soft Technologies Private Limited", logo="")

        why_join_points = [
            ("Highest Number of Placements in Top MNCs", "Microsoft, Amazon, IBM, Wipro Infosys, Accenture, Capgemini etc."),
            ("Top-tier labs", "Backed by industry giants like Nasscom Foundation and Semiance Center of Excellence."),
            ("Distinguished faculty", "Industry experts lead students using cutting-edge teaching tools and real-world projects."),
        ]
        for title, desc in why_join_points:
            WhyJoin.objects.get_or_create(course=course, title=title, description=desc)

        CourseHighlight.objects.get_or_create(course=course, title="High Demand and Employability", description="Tech industry is expanding rapidly.", icon="")
        CourseHighlight.objects.get_or_create(course=course, title="Attractive Salaries", description="High starting salaries and global opportunities.", icon="")

        CourseImage.objects.get_or_create(course=course, image="courses/gallery/image1.jpg", title="Industrial Visit 1", is_banner=False)
        CourseImage.objects.get_or_create(course=course, image="courses/gallery/image2.jpg", title="Industrial Visit 2", is_banner=False)

        Testimonial.objects.get_or_create(
            course=course,
            name="John Doe",
            position="Software Engineer",
            company="TechCorp",
            content="The B.Tech CSE program gave me the skills and confidence to succeed in the tech industry.",
            photo=""
        )

        self.stdout.write(self.style.SUCCESS('Seeded btech-hons-cse and related data.'))
