"""
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 TYPE_CHECKING, Any, Dict, Type, TypeVar, Union, cast

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

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.pr_curve import PRCurve
    from ..models.roc_curve import ROCCurve


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


@_attrs_define
class ClassificationMetrics:
    """
    Attributes:
        f1_score (float):
        accuracy (float):
        loss (float):
        anomaly_score_mean (Union[None, Unset, float]):
        anomaly_score_median (Union[None, Unset, float]):
        anomaly_score_variance (Union[None, Unset, float]):
        roc_auc (Union[None, Unset, float]):
        pr_auc (Union[None, Unset, float]):
        pr_curve (Union['PRCurve', None, Unset]):
        roc_curve (Union['ROCCurve', None, Unset]):
    """

    f1_score: float
    accuracy: 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
    roc_auc: Union[None, Unset, float] = UNSET
    pr_auc: Union[None, Unset, float] = UNSET
    pr_curve: Union["PRCurve", None, Unset] = UNSET
    roc_curve: Union["ROCCurve", None, Unset] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        from ..models.pr_curve import PRCurve
        from ..models.roc_curve import ROCCurve

        f1_score = self.f1_score

        accuracy = self.accuracy

        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

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

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

        pr_curve: Union[Dict[str, Any], None, Unset]
        if isinstance(self.pr_curve, Unset):
            pr_curve = UNSET
        elif isinstance(self.pr_curve, PRCurve):
            pr_curve = self.pr_curve.to_dict()
        else:
            pr_curve = self.pr_curve

        roc_curve: Union[Dict[str, Any], None, Unset]
        if isinstance(self.roc_curve, Unset):
            roc_curve = UNSET
        elif isinstance(self.roc_curve, ROCCurve):
            roc_curve = self.roc_curve.to_dict()
        else:
            roc_curve = self.roc_curve

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "f1_score": f1_score,
                "accuracy": accuracy,
                "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
        if roc_auc is not UNSET:
            field_dict["roc_auc"] = roc_auc
        if pr_auc is not UNSET:
            field_dict["pr_auc"] = pr_auc
        if pr_curve is not UNSET:
            field_dict["pr_curve"] = pr_curve
        if roc_curve is not UNSET:
            field_dict["roc_curve"] = roc_curve

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: dict[str, Any]) -> T:
        from ..models.pr_curve import PRCurve
        from ..models.roc_curve import ROCCurve

        d = src_dict.copy()
        f1_score = d.pop("f1_score")

        accuracy = d.pop("accuracy")

        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))

        def _parse_roc_auc(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)

        roc_auc = _parse_roc_auc(d.pop("roc_auc", UNSET))

        def _parse_pr_auc(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)

        pr_auc = _parse_pr_auc(d.pop("pr_auc", UNSET))

        def _parse_pr_curve(data: object) -> Union["PRCurve", None, Unset]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                pr_curve_type_0 = PRCurve.from_dict(data)

                return pr_curve_type_0
            except:  # noqa: E722
                pass
            return cast(Union["PRCurve", None, Unset], data)

        pr_curve = _parse_pr_curve(d.pop("pr_curve", UNSET))

        def _parse_roc_curve(data: object) -> Union["ROCCurve", None, Unset]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, dict):
                    raise TypeError()
                roc_curve_type_0 = ROCCurve.from_dict(data)

                return roc_curve_type_0
            except:  # noqa: E722
                pass
            return cast(Union["ROCCurve", None, Unset], data)

        roc_curve = _parse_roc_curve(d.pop("roc_curve", UNSET))

        classification_metrics = cls(
            f1_score=f1_score,
            accuracy=accuracy,
            loss=loss,
            anomaly_score_mean=anomaly_score_mean,
            anomaly_score_median=anomaly_score_median,
            anomaly_score_variance=anomaly_score_variance,
            roc_auc=roc_auc,
            pr_auc=pr_auc,
            pr_curve=pr_curve,
            roc_curve=roc_curve,
        )

        classification_metrics.additional_properties = d
        return classification_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
