from sqlmodel import Session, select
from database import engine, create_db_and_tables
from models import Vertical, Venue, Show, Song, Performance, User
from datetime import datetime

def seed_data():
    with Session(engine) as session:
        # Check if data exists
        existing_vertical = session.exec(select(Vertical)).first()
        if existing_vertical:
            print("Data already seeded.")
            return

        # Create Vertical
        phish = Vertical(name="Phish", slug="phish", description="The band Phish.")
        session.add(phish)
        session.commit()
        session.refresh(phish)

        # Create Venue
        msg = Venue(name="Madison Square Garden", city="New York", state="NY", country="USA", capacity=20000)
        session.add(msg)
        session.commit()
        session.refresh(msg)

        # Create Show
        show = Show(date=datetime(2023, 12, 31), vertical_id=phish.id, venue_id=msg.id)
        session.add(show)
        session.commit()
        session.refresh(show)

        # Create Songs
        song1 = Song(title="Gamehendge Time Phactory", vertical_id=phish.id)
        song2 = Song(title="Auld Lang Syne", vertical_id=phish.id)
        session.add(song1)
        session.add(song2)
        session.commit()
        session.refresh(song1)
        session.refresh(song2)

        # Create Performances
        p1 = Performance(show_id=show.id, song_id=song1.id, position=1, set_name="Set 1")
        p2 = Performance(show_id=show.id, song_id=song2.id, position=2, set_name="Set 1", segue=True)
        session.add(p1)
        session.add(p2)
        session.commit()

        print("Seeding complete!")

if __name__ == "__main__":
    # create_db_and_tables() # Alembic handles this now
    seed_data()
