# 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 CoreTagGetTagindexPerAreaParametersTagindex(BaseModel):
    """
    parameters
    """ # noqa: E501
    ctx: Optional[StrictInt] = Field(default=0, description="context id where to search for items")
    excl: Optional[StrictBool] = Field(default=False, description="exlusive mode for this tag area")
    var_from: Optional[StrictInt] = Field(default=0, description="context id where the link was displayed", alias="from")
    id: Optional[StrictInt] = Field(default=0, description="tag id")
    page: Optional[StrictInt] = Field(default=0, description="page number (0-based)")
    rec: Optional[StrictInt] = Field(default=0, description="search in the context recursive")
    ta: Optional[StrictInt] = Field(default=0, description="tag area id")
    tag: Optional[StrictStr] = Field(default='', description="tag name")
    tc: Optional[StrictInt] = Field(default=0, description="tag collection id")
    __properties: ClassVar[List[str]] = ["ctx", "excl", "from", "id", "page", "rec", "ta", "tag", "tc"]

    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 CoreTagGetTagindexPerAreaParametersTagindex 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 ctx (nullable) is None
        # and model_fields_set contains the field
        if self.ctx is None and "ctx" in self.model_fields_set:
            _dict['ctx'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "ctx": obj.get("ctx") if obj.get("ctx") is not None else 0,
            "excl": obj.get("excl") if obj.get("excl") is not None else False,
            "from": obj.get("from") if obj.get("from") is not None else 0,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "page": obj.get("page") if obj.get("page") is not None else 0,
            "rec": obj.get("rec") if obj.get("rec") is not None else 0,
            "ta": obj.get("ta") if obj.get("ta") is not None else 0,
            "tag": obj.get("tag") if obj.get("tag") is not None else '',
            "tc": obj.get("tc") if obj.get("tc") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


