"""Keep engine evidence separate from the official score shown in match lists."""
def result_fields(match):
    if match is None:
        return {"home_score": None, "away_score": None, "result_state": "UNPLAYED"}
    if match.status == "IN_PROGRESS":
        return {"home_score": match.home_score, "away_score": match.away_score, "result_state": "LIVE"}
    if match.status != "COMPLETED":
        return {"home_score": None, "away_score": None, "result_state": "UNPLAYED"}
    from match_result_governance.services import (
        ResultProjectionService, MatchResultCertificationService,
    )
    result = ResultProjectionService.effective_result(match=match, require_final=False)
    if result is not None:
        return {
            "home_score": result["home_score"], "away_score": result["away_score"],
            "result_state": "FINAL" if result["final"] else "PROVISIONAL",
            "result_outcome": result["outcome"],
        }
    cert = MatchResultCertificationService.current(match) if match.status == "COMPLETED" else None
    state = "PENDING_CERTIFICATION" if match.status == "COMPLETED" else "UNPLAYED"
    if cert and cert.status == "CERTIFIED" and cert.outcome in {"VOID", "REPLAY_REQUIRED"}:
        state = cert.outcome
    return {
        "home_score": None, "away_score": None,
        "result_state": state,
        "result_outcome": cert.outcome if cert else None,
    }
