# backend/tests/test_api_calendar.py
# phase-16+: 일정 mock 시드 제거 → 기본은 빈 상태. 기능 테스트는 직접 생성.
from tests._factories import make_cal_event, make_meeting, make_meeting_action


def test_week_bundle_empty(client):
    r = client.get("/api/calendar/week")
    assert r.status_code == 200
    b = r.json()
    assert b["today"] == 8 and b["week"] == [7, 8, 9, 10, 11, 12, 13]
    assert b["weekdays"] == ["일", "월", "화", "수", "목", "금", "토"]
    # 일정 연결 전: 캘린더/이벤트/포커스 모두 비어 있음
    assert b["calendars"] == [] and b["events"] == [] and b["focus_blocks"] == []


def test_week_bundle_with_event(client, session):
    s, _ = session
    make_cal_event(s, id="e1", day=8, start="14:00", end="15:00", title="분기 전략 미팅",
                   cal="work", soon=True)
    b = client.get("/api/calendar/week").json()
    assert any(e["id"] == "e1" for e in b["events"])


def test_day_bundle_with_meeting_and_actions(client, session):
    s, _ = session
    make_cal_event(s, id="e3", day=8, start="10:00", end="10:30", title="팀 스탠드업", cal="team")
    make_meeting(s, event_id="e3", phase="done")
    make_meeting_action(s, id="ea1", event_id="e3", idx=0, text="피드백 정리",
                        when_text="오늘", source="event")
    b = client.get("/api/calendar/day/8").json()
    e3 = next(e for e in b["events"] if e["id"] == "e3")
    assert e3["has_meeting"] is True
    assert [a["text"] for a in e3["actions"]] == ["피드백 정리"]


def test_meeting_phase(client, session):
    s, _ = session
    make_cal_event(s, id="e3", title="팀 스탠드업", cal="team")
    make_meeting(s, event_id="e3", phase="done")
    assert client.get("/api/calendar/meetings/e3").json()["phase"] == "done"


def test_meeting_404(client):
    assert client.get("/api/calendar/meetings/nope").status_code == 404


def test_day_focus_blocks_empty(client):
    b = client.get("/api/calendar/day/8").json()
    assert b["focus_blocks"] == []  # 포커스 시드 제거
