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

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

from attrs import define as _attrs_define
from attrs import field as _attrs_field
from dateutil.parser import isoparse

from ..types import UNSET, Unset

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


@_attrs_define
class CountPredictionsRequest:
    """
    Attributes:
        model_id (Union[None, Unset, str]):
        tag (Union[None, Unset, str]):
        prediction_ids (Union[List[str], None, Unset]):
        start_timestamp (Union[None, Unset, datetime.datetime]):
        end_timestamp (Union[None, Unset, datetime.datetime]):
    """

    model_id: Union[None, Unset, str] = UNSET
    tag: Union[None, Unset, str] = UNSET
    prediction_ids: Union[List[str], None, Unset] = UNSET
    start_timestamp: Union[None, Unset, datetime.datetime] = UNSET
    end_timestamp: Union[None, Unset, datetime.datetime] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        model_id: Union[None, Unset, str]
        if isinstance(self.model_id, Unset):
            model_id = UNSET
        else:
            model_id = self.model_id

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

        prediction_ids: Union[List[str], None, Unset]
        if isinstance(self.prediction_ids, Unset):
            prediction_ids = UNSET
        elif isinstance(self.prediction_ids, list):
            prediction_ids = self.prediction_ids

        else:
            prediction_ids = self.prediction_ids

        start_timestamp: Union[None, Unset, str]
        if isinstance(self.start_timestamp, Unset):
            start_timestamp = UNSET
        elif isinstance(self.start_timestamp, datetime.datetime):
            start_timestamp = self.start_timestamp.isoformat()
        else:
            start_timestamp = self.start_timestamp

        end_timestamp: Union[None, Unset, str]
        if isinstance(self.end_timestamp, Unset):
            end_timestamp = UNSET
        elif isinstance(self.end_timestamp, datetime.datetime):
            end_timestamp = self.end_timestamp.isoformat()
        else:
            end_timestamp = self.end_timestamp

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if model_id is not UNSET:
            field_dict["model_id"] = model_id
        if tag is not UNSET:
            field_dict["tag"] = tag
        if prediction_ids is not UNSET:
            field_dict["prediction_ids"] = prediction_ids
        if start_timestamp is not UNSET:
            field_dict["start_timestamp"] = start_timestamp
        if end_timestamp is not UNSET:
            field_dict["end_timestamp"] = end_timestamp

        return field_dict

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

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

        model_id = _parse_model_id(d.pop("model_id", UNSET))

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

        tag = _parse_tag(d.pop("tag", UNSET))

        def _parse_prediction_ids(data: object) -> Union[List[str], None, Unset]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, list):
                    raise TypeError()
                prediction_ids_type_0 = cast(List[str], data)

                return prediction_ids_type_0
            except:  # noqa: E722
                pass
            return cast(Union[List[str], None, Unset], data)

        prediction_ids = _parse_prediction_ids(d.pop("prediction_ids", UNSET))

        def _parse_start_timestamp(data: object) -> Union[None, Unset, datetime.datetime]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                start_timestamp_type_0 = isoparse(data)

                return start_timestamp_type_0
            except:  # noqa: E722
                pass
            return cast(Union[None, Unset, datetime.datetime], data)

        start_timestamp = _parse_start_timestamp(d.pop("start_timestamp", UNSET))

        def _parse_end_timestamp(data: object) -> Union[None, Unset, datetime.datetime]:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                end_timestamp_type_0 = isoparse(data)

                return end_timestamp_type_0
            except:  # noqa: E722
                pass
            return cast(Union[None, Unset, datetime.datetime], data)

        end_timestamp = _parse_end_timestamp(d.pop("end_timestamp", UNSET))

        count_predictions_request = cls(
            model_id=model_id,
            tag=tag,
            prediction_ids=prediction_ids,
            start_timestamp=start_timestamp,
            end_timestamp=end_timestamp,
        )

        count_predictions_request.additional_properties = d
        return count_predictions_request

    @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
