from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
import os
class Command(BaseCommand):
    help="Ensure initial users from env"
    def handle(self,*args,**kwargs):
        au=os.getenv("ADMIN_USERNAME"); ap=os.getenv("ADMIN_PASSWORD")
        eu=os.getenv("USER_USERNAME"); ep=os.getenv("USER_PASSWORD")
        if au and ap:
            u,_=User.objects.get_or_create(username=au)
            u.is_staff=True; u.is_superuser=True; u.set_password(ap); u.save()
            self.stdout.write(self.style.SUCCESS(f"Admin ensured: {au}"))
        if eu and ep:
            u,_=User.objects.get_or_create(username=eu)
            u.is_staff=False; u.is_superuser=False; u.set_password(ep); u.save()
            self.stdout.write(self.style.SUCCESS(f"Editor ensured: {eu}"))
