"""
Migration to add email verification and password reset columns to user table.
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from sqlmodel import Session, create_engine, text
from database import DATABASE_URL

def add_email_verification_columns():
    engine = create_engine(DATABASE_URL)
    
    columns = [
        ('email_verified', 'BOOLEAN DEFAULT FALSE'),
        ('verification_token', 'VARCHAR'),
        ('verification_token_expires', 'TIMESTAMP'),
        ('reset_token', 'VARCHAR'),
        ('reset_token_expires', 'TIMESTAMP'),
    ]
    
    with Session(engine) as session:
        for col_name, col_type in columns:
            try:
                session.exec(text(f"""
                    ALTER TABLE "user" ADD COLUMN IF NOT EXISTS {col_name} {col_type}
                """))
                session.commit()
                print(f"✅ Added {col_name} to user")
            except Exception as e:
                print(f"⚠️ {col_name}: {e}")

if __name__ == "__main__":
    add_email_verification_columns()
