from sqlalchemy.orm import Session
from app.db.base import User
from app.db.session import SessionLocal
from app.core import security
from app.core.logging_config import setup_logging
import logging

setup_logging()
logger = logging.getLogger("admin_seed")

def create_admin_user(db: Session):
    admin_email = "admin@silviajewelry.com"
    existing = db.query(User).filter(User.email == admin_email).first()
    
    if not existing:
        logger.info(f"Creating superuser account: {admin_email}")
        admin = User(
            email=admin_email,
            hashed_password=security.get_password_hash("admin123"), # Ganti password ini di production
            full_name="Owner Silvia Jewelry",
            is_active=True,
            is_superuser=True
        )
        db.add(admin)
        db.commit()
        logger.info("Superuser created successfully! Email: admin@aurelia.com, Password: admin123")
    else:
        logger.info("Superuser account already exists.")

if __name__ == "__main__":
    db = SessionLocal()
    try:
        create_admin_user(db)
    finally:
        db.close()
