# coding: utf-8

"""
    RCABench API

    RCABench - A comprehensive root cause analysis benchmarking platform for microservices This API provides endpoints for managing datasets, algorithms, evaluations, and fault injections for root cause analysis in distributed systems and microservices architectures.

    The version of the OpenAPI document: 1.0.1
    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 pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from rcabench.openapi.models.dto_date_range import DtoDateRange
from rcabench.openapi.models.dto_number_range import DtoNumberRange
from rcabench.openapi.models.dto_search_filter import DtoSearchFilter
from rcabench.openapi.models.dto_sort_option import DtoSortOption
from typing import Optional, Set
from typing_extensions import Self

class DtoRoleSearchRequest(BaseModel):
    """
    DtoRoleSearchRequest
    """ # noqa: E501
    created_at: Optional[DtoDateRange] = Field(default=None, description="Common filters shortcuts")
    description_pattern: Optional[StrictStr] = Field(default=None, description="描述模糊匹配")
    display_name_pattern: Optional[StrictStr] = Field(default=None, description="显示名模糊匹配")
    exclude_fields: Optional[List[StrictStr]] = None
    filters: Optional[List[DtoSearchFilter]] = Field(default=None, description="Filters")
    include: Optional[List[StrictStr]] = Field(default=None, description="Include related entities")
    include_fields: Optional[List[StrictStr]] = Field(default=None, description="Include/Exclude fields")
    is_active: Optional[StrictBool] = None
    is_system: Optional[StrictBool] = Field(default=None, description="是否系统角色")
    keyword: Optional[StrictStr] = Field(default=None, description="Search keyword (for general text search)")
    name_pattern: Optional[StrictStr] = Field(default=None, description="Role-specific filter shortcuts")
    page: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, description="Pagination")
    permission_ids: Optional[List[StrictInt]] = Field(default=None, description="权限ID筛选")
    project_id: Optional[StrictInt] = None
    size: Optional[Annotated[int, Field(le=1000, strict=True, ge=1)]] = None
    sort: Optional[List[DtoSortOption]] = Field(default=None, description="Sort")
    status: Optional[List[StrictInt]] = None
    types: Optional[List[StrictStr]] = Field(default=None, description="角色类型筛选")
    updated_at: Optional[DtoDateRange] = None
    user_count: Optional[DtoNumberRange] = Field(default=None, description="用户数量范围")
    user_id: Optional[StrictInt] = None
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["created_at", "description_pattern", "display_name_pattern", "exclude_fields", "filters", "include", "include_fields", "is_active", "is_system", "keyword", "name_pattern", "page", "permission_ids", "project_id", "size", "sort", "status", "types", "updated_at", "user_count", "user_id"]

    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"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of DtoRoleSearchRequest 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 each item in filters (list)
        _items = []
        if self.filters:
            for _item_filters in self.filters:
                if _item_filters:
                    _items.append(_item_filters.to_dict())
            _dict['filters'] = _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 updated_at
        if self.updated_at:
            _dict['updated_at'] = self.updated_at.to_dict()
        # override the default output from pydantic by calling `to_dict()` of user_count
        if self.user_count:
            _dict['user_count'] = self.user_count.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: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of DtoRoleSearchRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "created_at": DtoDateRange.from_dict(obj["created_at"]) if obj.get("created_at") is not None else None,
            "description_pattern": obj.get("description_pattern"),
            "display_name_pattern": obj.get("display_name_pattern"),
            "exclude_fields": obj.get("exclude_fields"),
            "filters": [DtoSearchFilter.from_dict(_item) for _item in obj["filters"]] if obj.get("filters") is not None else None,
            "include": obj.get("include"),
            "include_fields": obj.get("include_fields"),
            "is_active": obj.get("is_active"),
            "is_system": obj.get("is_system"),
            "keyword": obj.get("keyword"),
            "name_pattern": obj.get("name_pattern"),
            "page": obj.get("page"),
            "permission_ids": obj.get("permission_ids"),
            "project_id": obj.get("project_id"),
            "size": obj.get("size"),
            "sort": [DtoSortOption.from_dict(_item) for _item in obj["sort"]] if obj.get("sort") is not None else None,
            "status": obj.get("status"),
            "types": obj.get("types"),
            "updated_at": DtoDateRange.from_dict(obj["updated_at"]) if obj.get("updated_at") is not None else None,
            "user_count": DtoNumberRange.from_dict(obj["user_count"]) if obj.get("user_count") is not None else None,
            "user_id": obj.get("user_id")
        })
        # 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


