"""
create_admin.py — Create the first superuser without a terminal.
=================================================================
BEFORE RUNNING: Edit the credentials below to your desired login.
AFTER RUNNING:  DELETE this file from the server immediately (it has passwords).

HOW TO USE via cPanel Setup Python App:
  1. Edit the USERNAME, EMAIL, PASSWORD values below.
  2. Open cPanel → Setup Python App → Edit your app.
  3. Scroll to "Execute Python Script".
  4. Enter path:  /home/CPANEL_USER/your-domain.com/create_admin.py
  5. Click "Run".
  6. !! DELETE this file from the server via File Manager immediately !!
"""
import os
import sys
import django
from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent
sys.path.insert(0, str(BASE_DIR))

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()

from django.contrib.auth import get_user_model  # noqa: E402

# ====================================================
# EDIT THESE VALUES BEFORE RUNNING
USERNAME  = 'admin'
EMAIL     = 'admin@example.com'
PASSWORD  = 'ChangeThisPassword123!'
FULL_NAME = 'Site Admin'
# ====================================================

User = get_user_model()
if User.objects.filter(username=USERNAME).exists():
    print(f"User '{USERNAME}' already exists — no changes made.")
else:
    user = User.objects.create_superuser(
        username=USERNAME,
        email=EMAIL,
        password=PASSWORD,
    )
    print("=" * 50)
    print(f"Superuser created successfully!")
    print(f"  Username : {USERNAME}")
    print(f"  Email    : {EMAIL}")
    print(f"  Password : {PASSWORD}")
    print("=" * 50)
    print("IMPORTANT: Delete this file from the server NOW!")
    print("IMPORTANT: Change the password at /admin/ immediately!")
    print("=" * 50)
