class BenchmarkResult:
    """
    A class to handle a unified object to store benchmark results.

    This class takes a dictionary of metrics and a reference field in the constructor,
    and provides methods to access the metrics.
    """

    def __init__(self, metrics: dict[str, float], reference_field: str):
        """
        Initialize a BenchmarkResult object.

        Args:
            metrics: A dictionary mapping field names to their values
            reference_field: The name of the reference field that must exist in the metrics dictionary

        Raises:
            ValueError: If the reference_field is not in the metrics dictionary
        """
        if reference_field not in metrics:
            raise ValueError(f"Reference field '{reference_field}' not found in metrics")

        self._metrics = metrics
        self._reference_field = reference_field

    def __str__(self) -> str:
        """
        Returns a string representation of the benchmark metrics.

        Returns:
            A formatted string showing all metrics and their values
        """
        return f"BenchmarkResult({', '.join(f'{field}={value:.2f}' for field, value in self._metrics.items())})"

    @property
    def metrics(self) -> float:
        """
        Get the value of the reference field.

        Returns:
            The value of the reference field
        """
        return self._metrics[self._reference_field]

    def get_fields(self) -> list[str]:
        """
        Get all available field names in the metrics dictionary.

        Returns:
            A list of all field names
        """
        return list(self._metrics.keys())

    def __getitem__(self, field: str) -> float:
        """
        Get the value of a specific field.
        """
        return self._metrics[field]

    def get(self, field: str) -> float:
        """
        Get the value of a specific field.

        Args:
            field: The name of the field to get

        Returns:
            The value of the specified field

        Raises:
            KeyError: If the field is not in the metrics dictionary
        """
        if field not in self._metrics:
            raise KeyError(f"Field '{field}' not found in metrics")

        return self._metrics[field]
