# coding: utf-8

"""
    Moodle Webservice API

    Auto-generated OpenAPI spec for Moodle's Webservice API.

    The version of the OpenAPI document: 5.0.3 (Build: 20251006)
    Generated by OpenAPI Generator (https://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 import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class CoreSearchGetResultsParametersFilters(BaseModel):
    """
    filters to apply
    """ # noqa: E501
    areaids: Optional[List[Optional[StrictStr]]] = Field(default=None, description="restrict results to these areas")
    cat: Optional[StrictStr] = Field(default='', description="category to filter areas")
    contextids: Optional[List[Optional[StrictInt]]] = Field(default=None, description="restrict results to these contexts")
    courseids: Optional[List[Optional[StrictInt]]] = Field(default=None, description="restrict results to these courses")
    groupids: Optional[List[Optional[StrictInt]]] = Field(default=None, description="restrict results to these groups")
    mycoursesonly: Optional[StrictBool] = Field(default=False, description="only results from my courses")
    order: Optional[StrictStr] = Field(default='', description="how to order")
    timeend: Optional[StrictInt] = Field(default=0, description="docs modified before this date")
    timestart: Optional[StrictInt] = Field(default=0, description="docs modified after this date")
    title: Optional[StrictStr] = Field(default=None, description="result title")
    userids: Optional[List[Optional[StrictInt]]] = Field(default=None, description="restrict results to these users")
    __properties: ClassVar[List[str]] = ["areaids", "cat", "contextids", "courseids", "groupids", "mycoursesonly", "order", "timeend", "timestart", "title", "userids"]

    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 CoreSearchGetResultsParametersFilters 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.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if cat (nullable) is None
        # and model_fields_set contains the field
        if self.cat is None and "cat" in self.model_fields_set:
            _dict['cat'] = None

        # set to None if mycoursesonly (nullable) is None
        # and model_fields_set contains the field
        if self.mycoursesonly is None and "mycoursesonly" in self.model_fields_set:
            _dict['mycoursesonly'] = None

        # set to None if order (nullable) is None
        # and model_fields_set contains the field
        if self.order is None and "order" in self.model_fields_set:
            _dict['order'] = None

        # set to None if timeend (nullable) is None
        # and model_fields_set contains the field
        if self.timeend is None and "timeend" in self.model_fields_set:
            _dict['timeend'] = None

        # set to None if timestart (nullable) is None
        # and model_fields_set contains the field
        if self.timestart is None and "timestart" in self.model_fields_set:
            _dict['timestart'] = None

        # set to None if title (nullable) is None
        # and model_fields_set contains the field
        if self.title is None and "title" in self.model_fields_set:
            _dict['title'] = None

        return _dict

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

        relaxed = settings.relaxe_all_models or "CoreSearchGetResultsParametersFilters" in settings.relaxed_models

        if not isinstance(obj, dict):
            return cls.model_construct(**obj) if relaxed else cls.model_validate(obj)

        data = {
            "areaids": obj.get("areaids"),
            "cat": obj.get("cat") if obj.get("cat") is not None else '',
            "contextids": obj.get("contextids"),
            "courseids": obj.get("courseids"),
            "groupids": obj.get("groupids"),
            "mycoursesonly": obj.get("mycoursesonly") if obj.get("mycoursesonly") is not None else False,
            "order": obj.get("order") if obj.get("order") is not None else '',
            "timeend": obj.get("timeend") if obj.get("timeend") is not None else 0,
            "timestart": obj.get("timestart") if obj.get("timestart") is not None else 0,
            "title": obj.get("title"),
            "userids": obj.get("userids")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


