# 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, 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 CoreTagGetTagindexResponse(BaseModel):
    """
    tag index
    """ # noqa: E501
    anchor: Optional[StrictStr] = Field(default=None, description="name of anchor")
    component: Optional[StrictStr] = Field(description="component")
    content: Optional[StrictStr] = Field(description="title")
    exclusivetext: Optional[StrictStr] = Field(default=None, description="text for exclusive link")
    exclusiveurl: Optional[StrictStr] = Field(default=None, description="URL for exclusive link")
    hascontent: Optional[StrictInt] = Field(description="whether the content is present")
    itemtype: Optional[StrictStr] = Field(description="itemtype")
    nextpageurl: Optional[StrictStr] = Field(default=None, description="URL for the next page")
    prevpageurl: Optional[StrictStr] = Field(default=None, description="URL for the next page")
    ta: Optional[StrictInt] = Field(description="tag area id")
    tagid: Optional[StrictInt] = Field(description="tag id")
    title: Optional[StrictStr] = Field(description="title")
    __properties: ClassVar[List[str]] = ["anchor", "component", "content", "exclusivetext", "exclusiveurl", "hascontent", "itemtype", "nextpageurl", "prevpageurl", "ta", "tagid", "title"]

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

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

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

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

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

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

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

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

        # set to None if prevpageurl (nullable) is None
        # and model_fields_set contains the field
        if self.prevpageurl is None and "prevpageurl" in self.model_fields_set:
            _dict['prevpageurl'] = 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 tagid (nullable) is None
        # and model_fields_set contains the field
        if self.tagid is None and "tagid" in self.model_fields_set:
            _dict['tagid'] = 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 CoreTagGetTagindexResponse from a dict"""
        if obj is None:
            return None

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

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

        data = {
            "anchor": obj.get("anchor"),
            "component": obj.get("component"),
            "content": obj.get("content"),
            "exclusivetext": obj.get("exclusivetext"),
            "exclusiveurl": obj.get("exclusiveurl"),
            "hascontent": obj.get("hascontent"),
            "itemtype": obj.get("itemtype"),
            "nextpageurl": obj.get("nextpageurl"),
            "prevpageurl": obj.get("prevpageurl"),
            "ta": obj.get("ta"),
            "tagid": obj.get("tagid"),
            "title": obj.get("title")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


