"""
This file is generated by the openapi-python-client tool via the generate_api_client.py script

It is a customized template from the openapi-python-client tool's default template:
https://github.com/openapi-generators/openapi-python-client/blob/861ef5622f10fc96d240dc9becb0edf94e61446c/openapi_python_client/templates/model.py.jinja

The main change is:
- Fix typing issues
"""

# flake8: noqa: C901

from typing import Any, Type, TypeVar, Union, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

T = TypeVar("T", bound="RegressionMetrics")


@_attrs_define
class RegressionMetrics:
    """
    Attributes:
        mse (float):
        rmse (float):
        mae (float):
        r2 (float):
        explained_variance (float):
        loss (float):
        anomaly_score_mean (Union[None, Unset, float]):
        anomaly_score_median (Union[None, Unset, float]):
        anomaly_score_variance (Union[None, Unset, float]):
    """

    mse: float
    rmse: float
    mae: float
    r2: float
    explained_variance: float
    loss: float
    anomaly_score_mean: Union[None, Unset, float] = UNSET
    anomaly_score_median: Union[None, Unset, float] = UNSET
    anomaly_score_variance: Union[None, Unset, float] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        mse = self.mse

        rmse = self.rmse

        mae = self.mae

        r2 = self.r2

        explained_variance = self.explained_variance

        loss = self.loss

        anomaly_score_mean: Union[None, Unset, float]
        if isinstance(self.anomaly_score_mean, Unset):
            anomaly_score_mean = UNSET
        else:
            anomaly_score_mean = self.anomaly_score_mean

        anomaly_score_median: Union[None, Unset, float]
        if isinstance(self.anomaly_score_median, Unset):
            anomaly_score_median = UNSET
        else:
            anomaly_score_median = self.anomaly_score_median

        anomaly_score_variance: Union[None, Unset, float]
        if isinstance(self.anomaly_score_variance, Unset):
            anomaly_score_variance = UNSET
        else:
            anomaly_score_variance = self.anomaly_score_variance

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "mse": mse,
                "rmse": rmse,
                "mae": mae,
                "r2": r2,
                "explained_variance": explained_variance,
                "loss": loss,
            }
        )
        if anomaly_score_mean is not UNSET:
            field_dict["anomaly_score_mean"] = anomaly_score_mean
        if anomaly_score_median is not UNSET:
            field_dict["anomaly_score_median"] = anomaly_score_median
        if anomaly_score_variance is not UNSET:
            field_dict["anomaly_score_variance"] = anomaly_score_variance

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: dict[str, Any]) -> T:
        d = src_dict.copy()
        mse = d.pop("mse")

        rmse = d.pop("rmse")

        mae = d.pop("mae")

        r2 = d.pop("r2")

        explained_variance = d.pop("explained_variance")

        loss = d.pop("loss")

        def _parse_anomaly_score_mean(data: object) -> Union[None, Unset, float]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(Union[None, Unset, float], data)

        anomaly_score_mean = _parse_anomaly_score_mean(d.pop("anomaly_score_mean", UNSET))

        def _parse_anomaly_score_median(data: object) -> Union[None, Unset, float]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(Union[None, Unset, float], data)

        anomaly_score_median = _parse_anomaly_score_median(d.pop("anomaly_score_median", UNSET))

        def _parse_anomaly_score_variance(data: object) -> Union[None, Unset, float]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(Union[None, Unset, float], data)

        anomaly_score_variance = _parse_anomaly_score_variance(d.pop("anomaly_score_variance", UNSET))

        regression_metrics = cls(
            mse=mse,
            rmse=rmse,
            mae=mae,
            r2=r2,
            explained_variance=explained_variance,
            loss=loss,
            anomaly_score_mean=anomaly_score_mean,
            anomaly_score_median=anomaly_score_median,
            anomaly_score_variance=anomaly_score_variance,
        )

        regression_metrics.additional_properties = d
        return regression_metrics

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
