# 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.mod_assign_get_submission_status_response_lastattempt_submission import ModAssignGetSubmissionStatusResponseLastattemptSubmission
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModAssignGetSubmissionStatusResponseLastattempt(BaseModel):
    """
    Last attempt information.
    """ # noqa: E501
    blindmarking: Optional[StrictBool] = Field(description="Whether blind marking is enabled.")
    canedit: Optional[StrictBool] = Field(description="Whether the user can edit the current submission.")
    caneditowner: Optional[StrictBool] = Field(description="Whether the owner of the submission can edit it.")
    cansubmit: Optional[StrictBool] = Field(description="Whether the user can submit.")
    extensionduedate: Optional[StrictInt] = Field(description="Extension due date.")
    graded: Optional[StrictBool] = Field(description="Whether the submission is graded.")
    gradingstatus: Optional[StrictStr] = Field(description="Grading status.")
    locked: Optional[StrictBool] = Field(description="Whether new submissions are locked.")
    submission: Optional[ModAssignGetSubmissionStatusResponseLastattemptSubmission] = None
    submissiongroup: Optional[StrictInt] = Field(default=None, description="The submission group id (for group submissions only).")
    submissiongroupmemberswhoneedtosubmit: Optional[List[Optional[StrictInt]]] = Field(default=None, description="List of users who still need to submit (for group submissions only).")
    submissionsenabled: Optional[StrictBool] = Field(description="Whether submissions are enabled or not.")
    teamsubmission: Optional[ModAssignGetSubmissionStatusResponseLastattemptSubmission] = None
    timelimit: Optional[StrictInt] = Field(default=None, description="Time limit for submission.")
    usergroups: List[Optional[StrictInt]] = Field(description="User groups in the course.")
    __properties: ClassVar[List[str]] = ["blindmarking", "canedit", "caneditowner", "cansubmit", "extensionduedate", "graded", "gradingstatus", "locked", "submission", "submissiongroup", "submissiongroupmemberswhoneedtosubmit", "submissionsenabled", "teamsubmission", "timelimit", "usergroups"]

    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 ModAssignGetSubmissionStatusResponseLastattempt 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 submission
        if self.submission:
            _dict['submission'] = self.submission.to_dict()
        # override the default output from pydantic by calling `to_dict()` of teamsubmission
        if self.teamsubmission:
            _dict['teamsubmission'] = self.teamsubmission.to_dict()
        # set to None if blindmarking (nullable) is None
        # and model_fields_set contains the field
        if self.blindmarking is None and "blindmarking" in self.model_fields_set:
            _dict['blindmarking'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "blindmarking": obj.get("blindmarking"),
            "canedit": obj.get("canedit"),
            "caneditowner": obj.get("caneditowner"),
            "cansubmit": obj.get("cansubmit"),
            "extensionduedate": obj.get("extensionduedate"),
            "graded": obj.get("graded"),
            "gradingstatus": obj.get("gradingstatus"),
            "locked": obj.get("locked"),
            "submission": ModAssignGetSubmissionStatusResponseLastattemptSubmission.from_dict(obj["submission"]) if obj.get("submission") is not None else None,
            "submissiongroup": obj.get("submissiongroup"),
            "submissiongroupmemberswhoneedtosubmit": obj.get("submissiongroupmemberswhoneedtosubmit"),
            "submissionsenabled": obj.get("submissionsenabled"),
            "teamsubmission": ModAssignGetSubmissionStatusResponseLastattemptSubmission.from_dict(obj["teamsubmission"]) if obj.get("teamsubmission") is not None else None,
            "timelimit": obj.get("timelimit"),
            "usergroups": obj.get("usergroups")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


