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

class Command(BaseCommand):
    help = "Create a superuser with the specified username, email, and password."

    def add_arguments(self, parser):
        parser.add_argument("username")
        parser.add_argument("email")
        parser.add_argument("password")

    def handle(self, *args, **options):
        User = get_user_model()
        username = options["username"]
        email = options["email"]
        password = options["password"]
        try:
            # check if superuser already exists
            admin = User.objects.get(username=username)
        except User.DoesNotExist:
            # create superuser if it doesn"t exist
            admin = User.objects.create_superuser(username, email, password)
            self.stdout.write(self.style.SUCCESS(f"Successfully created superuser: {username}"))
        else:
            self.stdout.write(self.style.WARNING(f"Superuser already exists: {username}"))