from dataclasses import dataclass, field
from typing import Any, List, Optional

from typing_extensions import TypeAlias


ModelIndexSet: TypeAlias = "List[ModelIndex]"


@dataclass
class ModelIndex:
    name: str
    results: "List[SingleResult]"


@dataclass
class SingleMetric:
    type: str
    """
    Example: wer. Use metric id from https://hf.co/metrics
    """

    value: Any
    """
    Example: 20.0 or "20.0 ± 1.2"
    """

    name: Optional[str] = None
    """
    Example: Test WER
    """

    config: Optional[str] = None
    """
    The name of the metric configuration used in `load_metric()`. Example: bleurt-large-512 in `load_metric("bleurt", "bleurt-large-512")`. \
    See the `datasets` docs for more info: https://huggingface.co/docs/datasets/v2.1.0/en/loading#load-configurations
    """

    args: Any = field(default=None)
    """
    The arguments passed during `Metric.compute()`. Example for `bleu`: max_order: 4
    """

    verified: Optional[bool] = None
    """
    If true, indicates that evaluation was generated by Hugging Face (vs. self-reported).
    """


@dataclass
class SingleResultTask:
    type: str
    """
    Example: automatic-speech-recognition Use task id from
    hhttps://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts
    """

    name: Optional[str] = None
    """
    Example: Speech Recognition
    """


@dataclass
class SingleResultDataset:
    name: str
    """
    Example: Common Voice (French). A pretty name for the dataset.
    """

    type: str
    """
    Example: common_voice. Use dataset id from https://hf.co/datasets
    """

    config: Optional[str] = None
    """
    Example: fr. The name of the dataset configuration used in `load_dataset()`
    """

    split: Optional[str] = None
    """
    Example: test.
    """

    revision: Optional[str] = None
    """
    Example: 5503434ddd753f426f4b38109466949a1217c2bb.
    """

    args: Any = None
    """
    Optional. Additional arguments to `load_dataset()`. Example for wikipedia: { language: "en" }
    """


@dataclass
class SingleResult:
    task: "SingleResultTask"
    dataset: "Optional[SingleResultDataset]"
    """
    This will switch to required at some point. in any case, we need them to
    link to PWC
    """
    metrics: "List[SingleMetric]"
