"""Create default admin user"""

import asyncio
import sys

sys.path.insert(0, ".")

from app.core.security import get_password_hash
from app.db.session import engine, async_session_factory
from app.models.user import User


async def create_admin():
    from sqlalchemy import text

    async with async_session_factory() as session:
        result = await session.execute(text("SELECT id FROM users WHERE username = 'admin'"))
        if result.fetchone():
            print("Admin user already exists")
            return

        admin = User(
            username="admin",
            email="admin@planet.local",
            password_hash=get_password_hash("admin123"),
            role="super_admin",
            is_active=True,
        )
        session.add(admin)
        await session.commit()
        print("Admin user created: admin / admin123")


if __name__ == "__main__":
    asyncio.run(create_admin())
