# 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 poodle_async_full.models.tool_dataprivacy_create_purpose_form_response_purpose_formattedlawfulbases_inner import ToolDataprivacyCreatePurposeFormResponsePurposeFormattedlawfulbasesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ToolDataprivacyCreatePurposeFormResponsePurpose(BaseModel):
    """
    ToolDataprivacyCreatePurposeFormResponsePurpose
    """ # noqa: E501
    description: Optional[StrictStr] = Field(description="The purpose description.")
    descriptionformat: Optional[StrictInt] = Field(default=1, description="description format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    formattedlawfulbases: List[ToolDataprivacyCreatePurposeFormResponsePurposeFormattedlawfulbasesInner] = Field(description="formattedlawfulbases")
    formattedretentionperiod: StrictStr = Field(description="formattedretentionperiod")
    formattedsensitivedatareasons: Optional[List[ToolDataprivacyCreatePurposeFormResponsePurposeFormattedlawfulbasesInner]] = Field(default=None, description="formattedsensitivedatareasons")
    id: StrictInt = Field(description="id")
    lawfulbases: StrictStr = Field(description="Comma-separated IDs matching records in tool_dataprivacy_lawfulbasis.")
    name: StrictStr = Field(description="The purpose name.")
    protected: StrictInt = Field(description="Data retention with higher precedent over user's request to be forgotten.")
    retentionperiod: StrictStr = Field(description="Retention period. ISO_8601 durations format (as in DateInterval format).")
    roleoverrides: StrictStr = Field(description="roleoverrides")
    sensitivedatareasons: Optional[StrictStr] = Field(description="Comma-separated IDs matching records in tool_dataprivacy_sensitive")
    timecreated: StrictInt = Field(description="timecreated")
    timemodified: StrictInt = Field(description="timemodified")
    usermodified: StrictInt = Field(description="usermodified")
    __properties: ClassVar[List[str]] = ["description", "descriptionformat", "formattedlawfulbases", "formattedretentionperiod", "formattedsensitivedatareasons", "id", "lawfulbases", "name", "protected", "retentionperiod", "roleoverrides", "sensitivedatareasons", "timecreated", "timemodified", "usermodified"]

    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 ToolDataprivacyCreatePurposeFormResponsePurpose 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,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in formattedlawfulbases (list)
        _items = []
        if self.formattedlawfulbases:
            for _item_formattedlawfulbases in self.formattedlawfulbases:
                if _item_formattedlawfulbases:
                    _items.append(_item_formattedlawfulbases.to_dict())
            _dict['formattedlawfulbases'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in formattedsensitivedatareasons (list)
        _items = []
        if self.formattedsensitivedatareasons:
            for _item_formattedsensitivedatareasons in self.formattedsensitivedatareasons:
                if _item_formattedsensitivedatareasons:
                    _items.append(_item_formattedsensitivedatareasons.to_dict())
            _dict['formattedsensitivedatareasons'] = _items
        # set to None if description (nullable) is None
        # and model_fields_set contains the field
        if self.description is None and "description" in self.model_fields_set:
            _dict['description'] = None

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

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

        return _dict

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

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

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

        data = {
            "description": obj.get("description") if obj.get("description") is not None else '',
            "descriptionformat": obj.get("descriptionformat") if obj.get("descriptionformat") is not None else 1,
            "formattedlawfulbases": [ToolDataprivacyCreatePurposeFormResponsePurposeFormattedlawfulbasesInner.from_dict(_item) for _item in obj["formattedlawfulbases"]] if obj.get("formattedlawfulbases") is not None else None,
            "formattedretentionperiod": obj.get("formattedretentionperiod") if obj.get("formattedretentionperiod") is not None else '',
            "formattedsensitivedatareasons": [ToolDataprivacyCreatePurposeFormResponsePurposeFormattedlawfulbasesInner.from_dict(_item) for _item in obj["formattedsensitivedatareasons"]] if obj.get("formattedsensitivedatareasons") is not None else None,
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "lawfulbases": obj.get("lawfulbases") if obj.get("lawfulbases") is not None else '',
            "name": obj.get("name") if obj.get("name") is not None else '',
            "protected": obj.get("protected") if obj.get("protected") is not None else 0,
            "retentionperiod": obj.get("retentionperiod") if obj.get("retentionperiod") is not None else '',
            "roleoverrides": obj.get("roleoverrides") if obj.get("roleoverrides") is not None else '',
            "sensitivedatareasons": obj.get("sensitivedatareasons") if obj.get("sensitivedatareasons") is not None else '',
            "timecreated": obj.get("timecreated") if obj.get("timecreated") is not None else 0,
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "usermodified": obj.get("usermodified") if obj.get("usermodified") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


