# backend/tests/test_risk.py — 리스크 표시 (phase-16+: 작업 시드 제거 → 테스트가 직접 생성)
from datetime import date

from tests._factories import make_task


def _seed(s):
    make_task(s, id="k1", title="분기 리포트 초안 마무리", project_id="biz-report",
              status="doing", due=date(2026, 6, 8), assignee_id="jiwoo")
    make_task(s, id="dep-a", title="예산 섹션 작성", project_id="biz-report", status="todo")
    make_task(s, id="dep-b", title="경영진 검토 요청 메일", project_id="biz-report",
              status="todo", due=date(2026, 6, 10))


def test_risk_delay_present(client, session):
    s, _ = session
    _seed(s)
    r = client.get("/api/risks?area=work").json()
    kinds = [x["kind"] for x in r]
    assert "지연 위험" in kinds
    delay = next(x for x in r if x["kind"] == "지연 위험")
    assert "마감인데" in delay["text"] and delay["icon"] == "clock"


def test_risk_dependency(client, session):
    s, _ = session
    _seed(s)
    r = client.get("/api/risks?area=work").json()
    dep = [x for x in r if x["kind"] == "의존성"]
    assert dep, "예산 섹션 작성→경영진 검토 요청 메일 의존성 1건"
    assert "함께 밀려요" in dep[0]["text"]


def test_risk_max_three(client, session):
    s, _ = session
    _seed(s)
    r = client.get("/api/risks?area=work").json()
    assert len(r) <= 3


def test_risk_overload_threshold(client, session):
    s, _ = session
    _seed(s)
    r = client.get("/api/risks?area=work").json()
    over = [x for x in r if x["kind"] == "업무 쏠림"]
    for o in over:
        assert o["icon"] == "scale" and o["tone"] == "amber"
