"""Seed the MasterSkill table so the candidate skill / technology dropdowns
(Key Skills, Technologies Used) have options.

Run:  python seed_master_skills.py

Idempotent — existing skills (unique name) are skipped. created_by/updated_by
are set to the first ADMIN user (both FKs are required on the model).
"""

import django
import os
import sys

SKILLS = [
    # Languages
    "Python", "Java", "JavaScript", "TypeScript", "C", "C++", "C#", "Go", "Rust",
    "Kotlin", "Swift", "PHP", "Ruby", "Scala", "R", "SQL", "Bash", "Perl",
    # Frontend
    "HTML", "CSS", "React", "Next.js", "Angular", "Vue.js", "Redux", "Tailwind CSS",
    "Bootstrap", "jQuery", "Sass", "Webpack", "Vite",
    # Backend / frameworks
    "Node.js", "Express.js", "Django", "Flask", "FastAPI", "Spring Boot", "Spring",
    ".NET", "ASP.NET", "Laravel", "Ruby on Rails", "NestJS", "GraphQL", "REST API",
    "Microservices", "gRPC",
    # Databases
    "PostgreSQL", "MySQL", "MongoDB", "Redis", "SQLite", "Oracle", "SQL Server",
    "Elasticsearch", "Cassandra", "DynamoDB", "Firebase",
    # Cloud / DevOps
    "AWS", "Azure", "Google Cloud", "Docker", "Kubernetes", "Terraform", "Ansible",
    "Jenkins", "GitHub Actions", "GitLab CI", "CI/CD", "Linux", "Nginx", "Kafka",
    "RabbitMQ",
    # Data / AI
    "Machine Learning", "Deep Learning", "Data Science", "Pandas", "NumPy",
    "TensorFlow", "PyTorch", "Scikit-learn", "NLP", "Computer Vision", "Power BI",
    "Tableau", "Apache Spark", "Airflow",
    # Mobile
    "Android", "iOS", "React Native", "Flutter",
    # Tools / practices
    "Git", "Jira", "Agile", "Scrum", "Postman", "Selenium", "Cypress", "Jest",
    "Unit Testing", "System Design", "Data Structures", "Algorithms",
    # Soft skills
    "Communication", "Leadership", "Problem Solving", "Teamwork", "Time Management",
]


def seed_master_skills():
    from django.contrib.auth import get_user_model
    from apps.master_skills.models import MasterSkill

    User = get_user_model()
    admin = User.objects.filter(role="ADMIN").order_by("id").first() or User.objects.order_by("id").first()
    if not admin:
        print("ERROR: no user found to own the skills (created_by/updated_by required).")
        sys.exit(1)

    existing = {n.lower() for n in MasterSkill.objects.values_list("name", flat=True)}
    created = 0
    for name in SKILLS:
        if name.lower() in existing:
            continue
        MasterSkill.objects.create(name=name, status="ACTIVE", created_by=admin, updated_by=admin)
        created += 1

    print(f"Seeded {created} new skill(s); {MasterSkill.objects.count()} total in master_skills.")


if __name__ == "__main__":
    sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.dev")
    django.setup()
    seed_master_skills()
