# backend/tests/test_focus.py
from app.services.focus import free_slots, suggest_focus


def test_free_slots_day8(client, session):
    s, _ = session
    slots = free_slots(s, 8)
    assert any(b - a >= 60 for a, b in slots)  # 큰 빈 블록 1+ 존재
    sug = suggest_focus(s, 8, min_minutes=20)
    assert any(f.type == "deep" for f in sug)  # deep 제안 존재


def test_focus_suggest_endpoint(client):
    r = client.post(
        "/api/calendar/focus/suggest", json={"day": 8, "min_minutes": 20, "create": False}
    )
    assert r.status_code == 200
    data = r.json()
    assert data["day"] == 8 and data["created"] is False
    assert len(data["suggestions"]) >= 1


def test_focus_suggest_create_persists(client):
    # day 9 는 시드 집중 블록이 없음 → create=True 후 day/9 번들에 등장해야 함
    assert client.get("/api/calendar/day/9").json()["focus_blocks"] == []
    client.post("/api/calendar/focus/suggest", json={"day": 9, "min_minutes": 30, "create": True})
    after = client.get("/api/calendar/day/9").json()["focus_blocks"]
    assert len(after) >= 1
