from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar

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

if TYPE_CHECKING:
    from ..models.evaluation_dataset import EvaluationDataset


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


@_attrs_define
class DatasetListResponse:
    """Response model for listing datasets.

    Attributes:
        datasets (list[EvaluationDataset]): List of datasets
        total (int): Total number of datasets
        page (int): Current page number
        page_size (int): Items per page
    """

    datasets: list[EvaluationDataset]
    total: int
    page: int
    page_size: int
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        datasets = []
        for datasets_item_data in self.datasets:
            datasets_item = datasets_item_data.to_dict()
            datasets.append(datasets_item)

        total = self.total

        page = self.page

        page_size = self.page_size

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "datasets": datasets,
                "total": total,
                "page": page,
                "page_size": page_size,
            }
        )

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.evaluation_dataset import EvaluationDataset

        d = dict(src_dict)
        datasets = []
        _datasets = d.pop("datasets")
        for datasets_item_data in _datasets:
            datasets_item = EvaluationDataset.from_dict(datasets_item_data)

            datasets.append(datasets_item)

        total = d.pop("total")

        page = d.pop("page")

        page_size = d.pop("page_size")

        dataset_list_response = cls(
            datasets=datasets,
            total=total,
            page=page,
            page_size=page_size,
        )

        dataset_list_response.additional_properties = d
        return dataset_list_response

    @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
