"""
RCABench API

RCABench - A comprehensive root cause analysis benchmarking platform for microservices

The version of the OpenAPI document: 1.1.47
Contact: team@rcabench.com
Generated by OpenAPI Generator (https://rcabench.openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
from typing import Any, ClassVar

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing_extensions import Self

from rcabench.openapi.models.chaos_chaos_type import ChaosChaosType
from rcabench.openapi.models.datapack_state import DatapackState
from rcabench.openapi.models.date_range import DateRange
from rcabench.openapi.models.label_item import LabelItem
from rcabench.openapi.models.page_size import PageSize
from rcabench.openapi.models.sort_option import SortOption
from rcabench.openapi.models.status_type import StatusType


class SearchInjectionReq(BaseModel):
    """
    SearchInjectionReq
    """  # noqa: E501

    benchmarks: list[StrictStr] | None = None
    created_at: DateRange | None = None
    end_time: DateRange | None = None
    fault_types: list[ChaosChaosType] | None = None
    include_labels: StrictBool | None = Field(default=None, description="Whether to include labels in the response")
    include_task: StrictBool | None = Field(default=None, description="Whether to include task details in the response")
    labels: list[LabelItem] | None = Field(default=None, description="Custom labels to filter by")
    name_pattern: StrictStr | None = None
    names: list[StrictStr] | None = None
    page: StrictInt | None = None
    size: PageSize | None = None
    sort: list[SortOption] | None = None
    start_time: DateRange | None = None
    states: list[DatapackState] | None = None
    status: list[StatusType] | None = None
    task_ids: list[StrictStr] | None = None
    updated_at: DateRange | None = None
    additional_properties: dict[str, Any] = {}
    __properties: ClassVar[list[str]] = [
        "benchmarks",
        "created_at",
        "end_time",
        "fault_types",
        "include_labels",
        "include_task",
        "labels",
        "name_pattern",
        "names",
        "page",
        "size",
        "sort",
        "start_time",
        "states",
        "status",
        "task_ids",
        "updated_at",
    ]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return self.model_dump_json(by_alias=True, exclude_unset=True)

    @classmethod
    def from_json(cls, json_str: str) -> Self | None:
        """Create an instance of SearchInjectionReq from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: set[str] = set(
            [
                "additional_properties",
            ]
        )

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of created_at
        if self.created_at:
            _dict["created_at"] = self.created_at.to_dict()
        # override the default output from pydantic by calling `to_dict()` of end_time
        if self.end_time:
            _dict["end_time"] = self.end_time.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in labels (list)
        _items = []
        if self.labels:
            for _item_labels in self.labels:
                if _item_labels:
                    _items.append(_item_labels.to_dict())
            _dict["labels"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in sort (list)
        _items = []
        if self.sort:
            for _item_sort in self.sort:
                if _item_sort:
                    _items.append(_item_sort.to_dict())
            _dict["sort"] = _items
        # override the default output from pydantic by calling `to_dict()` of start_time
        if self.start_time:
            _dict["start_time"] = self.start_time.to_dict()
        # override the default output from pydantic by calling `to_dict()` of updated_at
        if self.updated_at:
            _dict["updated_at"] = self.updated_at.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

    @classmethod
    def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
        """Create an instance of SearchInjectionReq from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate(
            {
                "benchmarks": obj.get("benchmarks"),
                "created_at": DateRange.from_dict(obj["created_at"]) if obj.get("created_at") is not None else None,
                "end_time": DateRange.from_dict(obj["end_time"]) if obj.get("end_time") is not None else None,
                "fault_types": obj.get("fault_types"),
                "include_labels": obj.get("include_labels"),
                "include_task": obj.get("include_task"),
                "labels": [LabelItem.from_dict(_item) for _item in obj["labels"]]
                if obj.get("labels") is not None
                else None,
                "name_pattern": obj.get("name_pattern"),
                "names": obj.get("names"),
                "page": obj.get("page"),
                "size": obj.get("size"),
                "sort": [SortOption.from_dict(_item) for _item in obj["sort"]] if obj.get("sort") is not None else None,
                "start_time": DateRange.from_dict(obj["start_time"]) if obj.get("start_time") is not None else None,
                "states": obj.get("states"),
                "status": obj.get("status"),
                "task_ids": obj.get("task_ids"),
                "updated_at": DateRange.from_dict(obj["updated_at"]) if obj.get("updated_at") is not None else None,
            }
        )
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj
