"""
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, List, 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.class_representatives import ClassRepresentatives


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


@_attrs_define
class MemorysetClassPatternsMetrics:
    """
    Attributes:
        class_representatives (List['ClassRepresentatives']):
        mean_spread (float):
        variance_spread (float):
        mean_uniformity (float):
        variance_uniformity (float):
        patterns_description (Union[None, Unset, str]):
    """

    class_representatives: List["ClassRepresentatives"]
    mean_spread: float
    variance_spread: float
    mean_uniformity: float
    variance_uniformity: float
    patterns_description: Union[None, Unset, str] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        class_representatives = []
        for class_representatives_item_data in self.class_representatives:
            class_representatives_item = class_representatives_item_data.to_dict()
            class_representatives.append(class_representatives_item)

        mean_spread = self.mean_spread

        variance_spread = self.variance_spread

        mean_uniformity = self.mean_uniformity

        variance_uniformity = self.variance_uniformity

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "class_representatives": class_representatives,
                "mean_spread": mean_spread,
                "variance_spread": variance_spread,
                "mean_uniformity": mean_uniformity,
                "variance_uniformity": variance_uniformity,
            }
        )
        if patterns_description is not UNSET:
            field_dict["patterns_description"] = patterns_description

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: dict[str, Any]) -> T:
        from ..models.class_representatives import ClassRepresentatives

        d = src_dict.copy()
        class_representatives = []
        _class_representatives = d.pop("class_representatives")
        for class_representatives_item_data in _class_representatives:
            class_representatives_item = ClassRepresentatives.from_dict(class_representatives_item_data)

            class_representatives.append(class_representatives_item)

        mean_spread = d.pop("mean_spread")

        variance_spread = d.pop("variance_spread")

        mean_uniformity = d.pop("mean_uniformity")

        variance_uniformity = d.pop("variance_uniformity")

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

        patterns_description = _parse_patterns_description(d.pop("patterns_description", UNSET))

        memoryset_class_patterns_metrics = cls(
            class_representatives=class_representatives,
            mean_spread=mean_spread,
            variance_spread=variance_spread,
            mean_uniformity=mean_uniformity,
            variance_uniformity=variance_uniformity,
            patterns_description=patterns_description,
        )

        memoryset_class_patterns_metrics.additional_properties = d
        return memoryset_class_patterns_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
