from pathlib import Path
from typing import Union, Any

from attr import attrib
from attrs import field, define
from attrs.validators import instance_of, optional, deep_iterable
from src.data_classes.parameters_general import GeneralParameters


@define
class Metric:
    operation: str = field(validator=instance_of(str))
    column: str = field(validator=optional(instance_of(str)))


@define
class DescriptiveOverviewParameters(GeneralParameters):
    metrics: list[Union[Any, Metric]] = field(validator=instance_of(list))
    group_by: str = attrib(validator=instance_of(str))

    def __attrs_post_init__(self):
        self.metrics = [
            Metric(**metric) if isinstance(metric, dict) else metric
            for metric in self.metrics
        ]
        self.name_save_file: Path = Path(f"{self.name}")
