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

class Command(BaseCommand):
    help = "Create a default admin account with email admin@adtlas.com ."

    def handle(self, *args, **options):
        User = get_user_model()
        email = "admin@adtlas.com"
        password = "y2024@f329fx*ZCoUzV@p*"
        username = "admin"  
 
        try:
            # check if admin account already exists
            admin = User.objects.get(email=email)
        except User.DoesNotExist:
            # create admin account if it doesn"t exist
            admin = User.objects.create_superuser(email=email, password=password, username=username)
            self.stdout.write(self.style.SUCCESS(f"Successfully created default admin account with email {email}"))
        else:
            self.stdout.write(self.style.WARNING(f"Default admin account already exists with email {email}"))