# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from poodle_async_full.models.core_blog_get_entries_response_entries_inner_attachmentfiles_inner import CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModWorkshopGetSubmissionResponseSubmission(BaseModel):
    """
    ModWorkshopGetSubmissionResponseSubmission
    """ # noqa: E501
    attachment: Optional[StrictInt] = Field(description="Used by File API file_postupdate_standard_filemanager.")
    attachmentfiles: Optional[List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner]] = Field(default=None, description="attachmentfiles")
    authorid: StrictInt = Field(description="The author of the submission.")
    content: Optional[StrictStr] = Field(description="Submission text.")
    contentfiles: Optional[List[CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner]] = Field(default=None, description="contentfiles")
    contentformat: Optional[StrictInt] = Field(default=0, description="content format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    contenttrust: StrictInt = Field(description="The trust mode of the data.")
    example: Optional[StrictBool] = Field(description="Is this submission an example from teacher.")
    feedbackauthor: Optional[StrictStr] = Field(default=None, description="Teacher comment/feedback for the author of the submission, for example describing the reasons                     for the grade overriding.")
    feedbackauthorformat: Optional[StrictInt] = Field(default=0, description="feedbackauthor format (1 = HTML, 0 = MOODLE, 2 = PLAIN, or 4 = MARKDOWN)")
    grade: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Aggregated grade for the submission. The grade is a decimal number from interval 0..100.                     If NULL then the grade for submission has not been aggregated yet.")
    gradeover: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Grade for the submission manually overridden by a teacher. Grade is always from interval 0..100.                     If NULL then the grade is not overriden.")
    gradeoverby: Optional[StrictInt] = Field(default=None, description="The id of the user who has overridden the grade for submission.")
    id: StrictInt = Field(description="The primary key of the record.")
    late: StrictInt = Field(description="Has this submission been submitted after the deadline or during the assessment phase?")
    published: Optional[StrictBool] = Field(description="Shall the submission be available to other when the workshop is closed.")
    timecreated: StrictInt = Field(description="Timestamp when the work was submitted for the first time.")
    timegraded: Optional[StrictInt] = Field(default=None, description="The timestamp when grade or gradeover was recently modified.")
    timemodified: StrictInt = Field(description="Timestamp when the submission has been updated.")
    title: StrictStr = Field(description="The submission title.")
    workshopid: StrictInt = Field(description="The id of the workshop instance.")
    __properties: ClassVar[List[str]] = ["attachment", "attachmentfiles", "authorid", "content", "contentfiles", "contentformat", "contenttrust", "example", "feedbackauthor", "feedbackauthorformat", "grade", "gradeover", "gradeoverby", "id", "late", "published", "timecreated", "timegraded", "timemodified", "title", "workshopid"]

    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 ModWorkshopGetSubmissionResponseSubmission 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 attachmentfiles (list)
        _items = []
        if self.attachmentfiles:
            for _item_attachmentfiles in self.attachmentfiles:
                if _item_attachmentfiles:
                    _items.append(_item_attachmentfiles.to_dict())
            _dict['attachmentfiles'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in contentfiles (list)
        _items = []
        if self.contentfiles:
            for _item_contentfiles in self.contentfiles:
                if _item_contentfiles:
                    _items.append(_item_contentfiles.to_dict())
            _dict['contentfiles'] = _items
        # set to None if attachment (nullable) is None
        # and model_fields_set contains the field
        if self.attachment is None and "attachment" in self.model_fields_set:
            _dict['attachment'] = 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 example (nullable) is None
        # and model_fields_set contains the field
        if self.example is None and "example" in self.model_fields_set:
            _dict['example'] = None

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "attachment": obj.get("attachment") if obj.get("attachment") is not None else 0,
            "attachmentfiles": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["attachmentfiles"]] if obj.get("attachmentfiles") is not None else None,
            "authorid": obj.get("authorid") if obj.get("authorid") is not None else 0,
            "content": obj.get("content"),
            "contentfiles": [CoreBlogGetEntriesResponseEntriesInnerAttachmentfilesInner.from_dict(_item) for _item in obj["contentfiles"]] if obj.get("contentfiles") is not None else None,
            "contentformat": obj.get("contentformat") if obj.get("contentformat") is not None else 0,
            "contenttrust": obj.get("contenttrust") if obj.get("contenttrust") is not None else 0,
            "example": obj.get("example") if obj.get("example") is not None else False,
            "feedbackauthor": obj.get("feedbackauthor"),
            "feedbackauthorformat": obj.get("feedbackauthorformat") if obj.get("feedbackauthorformat") is not None else 0,
            "grade": obj.get("grade"),
            "gradeover": obj.get("gradeover"),
            "gradeoverby": obj.get("gradeoverby"),
            "id": obj.get("id") if obj.get("id") is not None else 0,
            "late": obj.get("late") if obj.get("late") is not None else 0,
            "published": obj.get("published") if obj.get("published") is not None else False,
            "timecreated": obj.get("timecreated") if obj.get("timecreated") is not None else 0,
            "timegraded": obj.get("timegraded"),
            "timemodified": obj.get("timemodified") if obj.get("timemodified") is not None else 0,
            "title": obj.get("title") if obj.get("title") is not None else '',
            "workshopid": obj.get("workshopid") if obj.get("workshopid") is not None else 0
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


