from __future__ import annotations

from sqlalchemy import select

from app.core.config import settings
from app.core.security import hash_password
from app.db.session import SessionLocal
from app.models.user import User, UserRole


def seed_admin() -> None:
    with SessionLocal() as session:
        existing = session.scalar(select(User).where(User.email == settings.admin_email.lower()))
        if existing is not None:
            return
        session.add(
            User(
                email=settings.admin_email.lower(),
                first_name="Validation Suite",
                last_name="Administrator",
                role=UserRole.ADMIN.value,
                password_hash=hash_password(settings.admin_password),
                is_active=True,
                must_change_password=False,
            )
        )
        session.commit()


if __name__ == "__main__":
    seed_admin()
