from fastapi.testclient import TestClient
from sqlmodel import Session
from models import Vertical, Show

def test_create_show(client: TestClient, session: Session, test_user_token: str):
    # 1. Create a Vertical first (needed for FK)
    vertical = Vertical(name="Phish", slug="phish")
    session.add(vertical)
    session.commit()
    
    # 2. Create Show
    response = client.post(
        "/shows/",
        json={
            "date": "2023-12-31T00:00:00",
            "vertical_id": vertical.id,
            "notes": "New Year's Eve"
        },
        headers={"Authorization": f"Bearer {test_user_token}"}
    )
    
    assert response.status_code == 200
    data = response.json()
    assert data["notes"] == "New Year's Eve"
    assert data["id"] is not None

from datetime import datetime

def test_read_shows(client: TestClient, session: Session):
    # Setup data
    vertical = Vertical(name="Goose", slug="goose")
    session.add(vertical)
    session.commit()
    
    show = Show(date=datetime(2024, 1, 1), vertical_id=vertical.id, notes="Test Show")
    session.add(show)
    session.commit()
    
    # Test Read
    response = client.get("/shows/")
    assert response.status_code == 200
    data = response.json()
    assert len(data) > 0
    assert data[0]["notes"] == "Test Show"

def test_attendance(client: TestClient, session: Session, test_user_token: str):
    # Setup
    vertical = Vertical(name="Test Band", slug="test-band")
    session.add(vertical)
    session.commit()
    show = Show(date=datetime(2024, 1, 1), vertical_id=vertical.id)
    session.add(show)
    session.commit()
    
    # Mark Attendance
    response = client.post(
        "/attendance/",
        json={"show_id": show.id},
        headers={"Authorization": f"Bearer {test_user_token}"}
    )
    assert response.status_code == 200
    assert response.json()["show_id"] == show.id
    
    # Verify in "My Attendance"
    response = client.get(
        "/attendance/me",
        headers={"Authorization": f"Bearer {test_user_token}"}
    )
    assert response.status_code == 200
    assert len(response.json()) == 1
