from __future__ import annotations

from contract_attestation.models import (
    AttestationStatus,
    EvidenceLevel,
    ReputationResult,
    ReviewResult,
    StatusResult,
)


def test_review_result_ignores_unknown_fields() -> None:
    payload = {
        "score": 90,
        "evidence_level": "full",
        "findings": [],
        "recommendations": [],
        "attestation": {},
        "attestation_status": "attested",
        "unknown_field": "ignored",
    }

    result = ReviewResult.model_validate(payload)

    assert result.score == 90
    assert result.evidence_level is EvidenceLevel.FULL
    assert result.attestation_status is AttestationStatus.ATTESTED
    assert not hasattr(result, "unknown_field")


def test_status_result_parses_not_found() -> None:
    payload = {
        "request_hash": "0x" + "11" * 32,
        "status": "not_found",
        "last_update": 0,
    }

    result = StatusResult.model_validate(payload)

    assert result.status.value == "not_found"
    assert result.last_update == 0


def test_reputation_result_allows_negative_summary_value() -> None:
    payload = {
        "agent_id": 297,
        "status": "ok",
        "feedback_count": 3,
        "summary_value": -150,
        "summary_value_decimals": 2,
        "summary_value_normalized": "-1.5",
        "client_count": 1,
    }

    result = ReputationResult.model_validate(payload)

    assert result.summary_value == -150
    assert result.summary_value_normalized == "-1.5"
