# backend/tests/test_api_calendar.py
def test_week_bundle(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 len(b["calendars"]) == 5 and len(b["events"]) == 22 and len(b["focus_blocks"]) == 4
    team = next(c for c in b["calendars"] if c["id"] == "team")
    assert team["count"] == sum(1 for e in b["events"] if e["cal"] == "team")


def test_day_bundle_has_meeting_and_actions(client):
    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 e3["meet_label"] == "회의 노트 · 액션 보기"
    assert [a["text"] for a in e3["actions"]] == [
        "온보딩 와이어프레임 피드백 정리",
        "푸시 알림 QA 결과 공유",
    ]
    e6 = next(e for e in b["events"] if e["id"] == "e6")
    assert e6["soon"] is True and e6["meet_label"] == "사전 브리핑 보기"
    assert e6["people"] == ["대표님", "재무팀장", "나 외 3명"]


def test_meeting_phases(client):
    assert client.get("/api/calendar/meetings/e3").json()["phase"] == "done"
    assert client.get("/api/calendar/meetings/e4").json()["phase"] == "live"
    up = client.get("/api/calendar/meetings/e6").json()
    assert up["phase"] == "upcoming" and len(up["agenda"]) == 3 and len(up["docs"]) == 2
    oo = client.get("/api/calendar/meetings/e7").json()
    assert oo["one_on_one"] is True and oo["person"]["name"] == "민서"
    assert len(oo["talking_points"]) == 3


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


def test_day_focus_blocks(client):
    b = client.get("/api/calendar/day/8").json()
    assert len(b["focus_blocks"]) == 4
    deep = [f for f in b["focus_blocks"] if f["type"] == "deep"]
    assert len(deep) == 1 and deep[0]["title"] == "분기 리포트 초안 마무리"
