#!/usr/bin/env python
"""Create a platform admin user for testing."""
import os
import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
django.setup()

from smoothschedule.identity.users.models import User
from rest_framework.authtoken.models import Token

# Create or get a superuser with platform admin role
user, created = User.objects.get_or_create(
    username='admin',
    defaults={
        'email': 'admin@smoothschedule.com',
        'is_staff': True,
        'is_superuser': True,
        'role': User.Role.SUPERUSER,
    }
)

if created:
    user.set_password('admin123')
    user.save()
    print(f"Created new superuser: {user.username}")
else:
    user.role = User.Role.SUPERUSER
    user.is_staff = True
    user.is_superuser = True
    user.set_password('admin123')
    user.save()
    print(f"Updated existing user: {user.username}")

# Create or get auth token
token, _ = Token.objects.get_or_create(user=user)
print(f"\nAuth token: {token.key}")
print(f"User role: {user.role}")
print(f"\nYou can now use this token to test the API:")
print(f'curl -H "Authorization: Token {token.key}" http://lvh.me:8000/api/platform/businesses/')
