import pytest

from app.calculator.core import calculate_saju
from app.calculator.monthly_flow import calculate_monthly_flow


def test_returns_12_entries():
    saju = calculate_saju(1990, 5, 15, 14, "male")
    flow = calculate_monthly_flow(saju, 2026)
    assert len(flow) == 12


def test_entries_have_required_keys():
    saju = calculate_saju(1990, 5, 15, 14, "male")
    flow = calculate_monthly_flow(saju, 2026)
    for i, entry in enumerate(flow):
        assert entry["month"] == i + 1
        for k in ("stem", "branch", "score", "label"):
            assert k in entry, f"month {i+1} missing {k}"
        assert 0 <= entry["score"] <= 100


def test_labels_are_valid():
    saju = calculate_saju(1990, 5, 15, 14, "male")
    flow = calculate_monthly_flow(saju, 2026)
    valid_labels = {"변동", "성장", "안정", "도전", "정체"}
    for entry in flow:
        assert entry["label"] in valid_labels


def test_different_sajus_different_flows():
    s1 = calculate_saju(1990, 5, 15, 14, "male")
    s2 = calculate_saju(1985, 1, 1, 0, "female")
    f1 = calculate_monthly_flow(s1, 2026)
    f2 = calculate_monthly_flow(s2, 2026)
    scores_1 = [e["score"] for e in f1]
    scores_2 = [e["score"] for e in f2]
    assert scores_1 != scores_2
