"""Script to create a default admin user."""
from sqlmodel import Session, select
from app.core.database import engine
from app.models.user import User, UserRole
from app.core.security import get_password_hash
from app.core.config import settings

def create_admin():
    with Session(engine) as session:
        # Check if admin already exists
        admin = session.exec(select(User).where(User.email == "admin@sibu.com")).first()
        if admin:
            print("Admin already exists.")
            return

        new_admin = User(
            email="admin@sibu.com",
            full_name="Administrator",
            hashed_password=get_password_hash(settings.admin_password),
            role=UserRole.ADMIN,
            is_verified=True
        )
        session.add(new_admin)
        session.commit()
        print("Admin user created successfully!")

if __name__ == "__main__":
    create_admin()
