# coding: utf-8

"""
    Moodle Webservice API

    Auto-generated OpenAPI spec for Moodle's Webservice API.

    The version of the OpenAPI document: 4.5.7 (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_mini.models.mod_assign_get_submissions_response_assignments_inner_submissions_inner_plugins_inner import ModAssignGetSubmissionsResponseAssignmentsInnerSubmissionsInnerPluginsInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_mini.configuration import settings

class ModAssignGetSubmissionsResponseAssignmentsInnerSubmissionsInner(BaseModel):
    """
    submission info
    """ # noqa: E501
    assignment: Optional[StrictInt] = Field(default=None, description="assignment id")
    attemptnumber: Optional[StrictInt] = Field(description="attempt number")
    gradingstatus: Optional[StrictStr] = Field(default=None, description="Grading status.")
    groupid: Optional[StrictInt] = Field(description="group id")
    id: Optional[StrictInt] = Field(description="submission id")
    latest: Optional[StrictInt] = Field(default=None, description="latest attempt")
    plugins: Optional[List[ModAssignGetSubmissionsResponseAssignmentsInnerSubmissionsInnerPluginsInner]] = Field(default=None, description="plugins")
    status: Optional[StrictStr] = Field(description="submission status")
    timecreated: Optional[StrictInt] = Field(description="submission creation time")
    timemodified: Optional[StrictInt] = Field(description="submission last modified time")
    timestarted: Optional[StrictInt] = Field(default=None, description="submission start time")
    userid: Optional[StrictInt] = Field(description="student id")
    __properties: ClassVar[List[str]] = ["assignment", "attemptnumber", "gradingstatus", "groupid", "id", "latest", "plugins", "status", "timecreated", "timemodified", "timestarted", "userid"]

    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 ModAssignGetSubmissionsResponseAssignmentsInnerSubmissionsInner 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 plugins (list)
        _items = []
        if self.plugins:
            for _item_plugins in self.plugins:
                if _item_plugins:
                    _items.append(_item_plugins.to_dict())
            _dict['plugins'] = _items
        # set to None if assignment (nullable) is None
        # and model_fields_set contains the field
        if self.assignment is None and "assignment" in self.model_fields_set:
            _dict['assignment'] = None

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "assignment": obj.get("assignment"),
            "attemptnumber": obj.get("attemptnumber"),
            "gradingstatus": obj.get("gradingstatus"),
            "groupid": obj.get("groupid"),
            "id": obj.get("id"),
            "latest": obj.get("latest"),
            "plugins": [ModAssignGetSubmissionsResponseAssignmentsInnerSubmissionsInnerPluginsInner.from_dict(_item) for _item in obj["plugins"]] if obj.get("plugins") is not None else None,
            "status": obj.get("status"),
            "timecreated": obj.get("timecreated"),
            "timemodified": obj.get("timemodified"),
            "timestarted": obj.get("timestarted"),
            "userid": obj.get("userid")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


