#!/usr/bin/env python3
"""Quick demo seeder - creates users and basic data"""
import sys
sys.path.insert(0, '/Users/ten/ANTIGRAVITY/elmeg-demo/backend')

from datetime import datetime, timedelta
from sqlmodel import Session
from passlib.context import CryptContext
from database import engine
from models import User, Vertical, Venue, Show, Song, Performance, UserPreferences

pwd_context = CryptContext(schemes=["argon2"], deprecated="auto")

print("Starting demo seed...")

with Session(engine) as session:
    # Create Goose vertical
    vertical = Vertical(name="Goose", slug="goose", description="Jam band from CT")
    session.add(vertical)
    session.commit()
    session.refresh(vertical)
    print(f"✓ Created vertical: {vertical.name}")
    
    # Create 12 users
    users_data = [
        ("archivist@demo.com", "TheArchivist", "user", True),
        ("statnerd@demo.com", "StatNerd420", "user", False),
        ("reviewer@demo.com", "CriticalListener", "user", False),
        ("casual@demo.com", "CasualFan", "user", False),
        ("groupleader@demo.com", "NortheastHonkers", "user", False),
        ("mod@demo.com", "ModGoose", "moderator", False),
        ("admin@demo.com", "AdminBird", "admin", False),
        ("newbie@demo.com", "NewToGoose", "user", False),
        ("taper@demo.com", "TaperTom", "user", False),
        ("tourfollower@demo.com", "RoadWarrior", "user", False),
        ("lurker@demo.com", "SilentHonker", "user", True),
        ("hype@demo.com", "HypeGoose", "user", False),
    ]
    
    users = []
    for email, username, role, wiki_mode in users_data:
        user = User(
            email=email,
            hashed_password=pwd_context.hash("demo123"),
            is_active=True,
            is_superuser=(role == "admin"),
            role=role
        )
        session.add(user)
        session.commit()
        session.refresh(user)
        
        prefs = UserPreferences(
            user_id=user.id,
            wiki_mode=wiki_mode,
            show_ratings=not wiki_mode,
            show_comments=not wiki_mode
        )
        session.add(prefs)
        users.append(user)
        print(f"✓ Created user: {username}")
    
    session.commit()
    
    # Create venues
    venues = [
        Venue(name="Red Rocks", city="Morrison", state="CO", country="USA"),
        Venue(name="Capitol Theatre", city="Port Chester", state="NY", country="USA"),
    ]
    for v in venues:
        session.add(v)
    session.commit()
    print(f"✓ Created {len(venues)} venues")
    
    # Create songs
    songs = [
        Song(title="Hungersite", vertical_id=vertical.id),
        Song(title="Arcadia", vertical_id=vertical.id),
        Song(title="Hot Tea", vertical_id=vertical.id),
    ]
    for s in songs:
        session.add(s)
    session.commit()
    print(f"✓ Created {len(songs)} songs")
    
    # Create shows
    shows = []
    for i in range(5):
        show = Show(
            date=datetime(2024, 1, 1) + timedelta(days=i*30),
            vertical_id=vertical.id,
            venue_id=venues[i % len(venues)].id
        )
        session.add(show)
        shows.append(show)
    session.commit()
    print(f"✓ Created {len(shows)} shows")
    
    # Create performances
    for show in shows:
        for pos, song in enumerate(songs, 1):
            perf = Performance(
                show_id=show.id,
                song_id=song.id,
                position=pos,
                set_name="Set 1"
            )
            session.add(perf)
    session.commit()
    print(f"✓ Created performances")
    
    print("\n" + "="*60)
    print("✓ DEMO DATA SEEDED!")
    print("="*60)
    print("\nAll passwords: demo123")
    print("\nStart demo server:")
    print("  cd /Users/ten/ANTIGRAVITY/elmeg-demo/backend")
    print("  DATABASE_URL='sqlite:///./elmeg-demo.db' uvicorn main:app --reload --port 8001")
