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

from poodle_async_full.configuration import settings

class ToolPolicyGetUserAcceptancesResponsePoliciesInner(BaseModel):
    """
    ToolPolicyGetUserAcceptancesResponsePoliciesInner
    """ # noqa: E501
    acceptance: Optional[ToolPolicyGetUserAcceptancesResponsePoliciesInnerAcceptance] = None
    agreementstyle: Optional[StrictInt] = Field(description="The policy agreement style. 0: consent page, 1: own page.")
    canaccept: Optional[StrictBool] = Field(description="Whether the policy can be accepted.")
    candecline: Optional[StrictBool] = Field(description="Whether the policy can be declined.")
    canrevoke: Optional[StrictBool] = Field(description="Whether the policy can be revoked.")
    content: Optional[StrictStr] = Field(default=None, description="The policy content.")
    contentformat: Optional[StrictInt] = Field(description="content format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    name: Optional[StrictStr] = Field(description="The policy name")
    optional: Optional[StrictInt] = Field(description="Whether the policy is optional. 0: compulsory, 1: optional")
    policyid: Optional[StrictInt] = Field(description="The policy id.")
    revision: Optional[StrictStr] = Field(description="The policy revision.")
    status: Optional[StrictInt] = Field(description="The policy status. 0: draft, 1: active, 2: archived.")
    summary: Optional[StrictStr] = Field(default=None, description="The policy summary.")
    summaryformat: Optional[StrictInt] = Field(description="summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    versionid: Optional[StrictInt] = Field(description="The policy version id.")
    __properties: ClassVar[List[str]] = ["acceptance", "agreementstyle", "canaccept", "candecline", "canrevoke", "content", "contentformat", "name", "optional", "policyid", "revision", "status", "summary", "summaryformat", "versionid"]

    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 ToolPolicyGetUserAcceptancesResponsePoliciesInner 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 acceptance
        if self.acceptance:
            _dict['acceptance'] = self.acceptance.to_dict()
        # set to None if agreementstyle (nullable) is None
        # and model_fields_set contains the field
        if self.agreementstyle is None and "agreementstyle" in self.model_fields_set:
            _dict['agreementstyle'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "acceptance": ToolPolicyGetUserAcceptancesResponsePoliciesInnerAcceptance.from_dict(obj["acceptance"]) if obj.get("acceptance") is not None else None,
            "agreementstyle": obj.get("agreementstyle"),
            "canaccept": obj.get("canaccept"),
            "candecline": obj.get("candecline"),
            "canrevoke": obj.get("canrevoke"),
            "content": obj.get("content"),
            "contentformat": obj.get("contentformat"),
            "name": obj.get("name"),
            "optional": obj.get("optional"),
            "policyid": obj.get("policyid"),
            "revision": obj.get("revision"),
            "status": obj.get("status"),
            "summary": obj.get("summary"),
            "summaryformat": obj.get("summaryformat"),
            "versionid": obj.get("versionid")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


