from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
import uuid

User = get_user_model()

class Command(BaseCommand):
    help = 'Creates a superuser with UUID support'

    def handle(self, *args, **options):
        if not User.objects.filter(is_superuser=True).exists():
            username = 'admin'
            email = 'admin@branchbusinessadvance.com'
            password = 'admin123'
            phone_number = '+254700000000'

            try:
                superuser = User.objects.create_superuser(
                    id=uuid.uuid4(),
                    username=username,
                    email=email,
                    password=password,
                    phone_number=phone_number,
                    is_active=True,
                    role='admin'
                )
                self.stdout.write(self.style.SUCCESS(f'Superuser created successfully with UUID: {superuser.id}'))
            except Exception as e:
                self.stdout.write(self.style.ERROR(f'Error creating superuser: {str(e)}'))
        else:
            self.stdout.write(self.style.WARNING('Superuser already exists')) 