from django.core.management.base import BaseCommand
from core.models import User, Notice, Event, Program, Faculty
from datetime import date


class Command(BaseCommand):
    help = "Seed initial superadmin + sample records"

    def handle(self, *args, **options):
        if not User.objects.filter(email="admin@newsummit.edu.np").exists():
            User.objects.create_superuser(
                email="admin@newsummit.edu.np",
                password="Admin@1234",
                full_name="Administrator",
            )
            self.stdout.write(self.style.SUCCESS("Superadmin  →  admin@newsummit.edu.np / Admin@1234"))

        if not User.objects.filter(email="editor@newsummit.edu.np").exists():
            User.objects.create_user(
                email="editor@newsummit.edu.np",
                password="Editor@1234",
                full_name="Content Editor",
                role="admin",
            )
            self.stdout.write(self.style.SUCCESS("Admin user  →  editor@newsummit.edu.np / Editor@1234"))

        admin = User.objects.get(email="admin@newsummit.edu.np")

        for title, cat, d in [
            ("BSc.CSIT Entrance Exam 2026 — Form Available", "exam",      date(2026, 4, 10)),
            ("Mid-Term Examination Schedule Published",       "exam",      date(2026, 4, 8)),
            ("Scholarship Application Deadline Extended",     "admission", date(2026, 4, 5)),
        ]:
            Notice.objects.get_or_create(title=title, defaults={"category": cat, "date": d, "created_by": admin})

        for title, d, loc, past in [
            ("Annual Cultural Festival 2026",       date(2026, 5, 15), "College Auditorium",    False),
            ("Tech Symposium: Future of Computing", date(2026, 5, 2),  "IT Lab & Seminar Hall", False),
        ]:
            Event.objects.get_or_create(title=title, defaults={"date": d, "location": loc, "is_past": past, "created_by": admin})

        for name, dept, dur, courses in [
            ("BSc.CSIT", "Science & IT", "8 Semesters", ["C Programming", "DBMS", "AI"]),
            ("BBA",      "Management",   "8 Semesters", ["Accounting", "Marketing"]),
        ]:
            Program.objects.get_or_create(name=name, defaults={"department": dept, "duration": dur, "courses": courses, "created_by": admin})

        self.stdout.write(self.style.SUCCESS("Seed complete."))
