import sys
import os
from sqlmodel import Session, select

# Add parent directory to path to import app
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app.core.database import engine
from app.models.user import User, UserRole
from app.core.security import get_password_hash

def create_promo_user():
    email = "promo@gmail.com"
    password = "promo"
    full_name = "Promociones SIBU"
    
    with Session(engine) as session:
        # Check if user already exists
        statement = select(User).where(User.email == email)
        user = session.exec(statement).first()
        
        if user:
            print(f"User {email} already exists.")
            # Update role to PROMOTER if necessary
            if user.role != UserRole.PROMOTER:
                user.role = UserRole.PROMOTER
                session.add(user)
                session.commit()
                print(f"Updated user {email} role to PROMOTER.")
            return
        
        # Create new user
        new_user = User(
            email=email,
            hashed_password=get_password_hash(password),
            full_name=full_name,
            role=UserRole.PROMOTER.value,
            is_active=True,
            is_verified=True
        )
        
        session.add(new_user)
        session.commit()
        print(f"User {email} created successfully.")

if __name__ == "__main__":
    create_promo_user()
