from typing import Any, cast

from pydantic import BaseModel


# https://docs.pact.io/implementation_guides/jvm/matching#matcher-selection-algorithm
def generate_matching_rules(model: type[BaseModel]) -> dict[str, dict[str, str]]:
    schema = model.model_json_schema()
    prop = cast(dict[str, Any], schema.get("properties", {}))
    result: dict[str, dict[str, str]] = {}
    for field, field_schema_raw in prop.items():  # pyright: ignore[reportAny]
        field_schema = cast(dict[str, Any], field_schema_raw)
        result[f"$.body.{field}"] = {
            "match": cast(str, field_schema.get("type", "string"))
        }
    return result
