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

class Command(BaseCommand):
    help = 'Creates the admin superuser'

    def handle(self, *args, **options):
        User = get_user_model()
        
        # Delete existing admin user if exists
        User.objects.filter(username='admin').delete()
        
        # Create new superuser
        admin = User.objects.create_superuser(
            username='admin',
            email='admin@branchbusinessadvance.com',
            password='admin123',
            phone_number='+254700000000',
            role='admin',
            first_name='Branch',
            last_name='Admin',
            is_staff=True,
            is_superuser=True,
            is_active=True,
            status='active'
        )
        
        self.stdout.write(self.style.SUCCESS('Successfully created admin user'))