# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 3.54.3-ai-plus
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

class ResourceCompletion(BaseModel):
    """
    Serializer for resource completion data used in both request and response. Inherits common completion fields from CompletableBaseSerializer.
    """ # noqa: E501
    completion_percentage: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Completion percentage")
    completed: Optional[StrictBool] = Field(default=False, description="Whether completable is completed")
    last_updated: datetime = Field(description="Last update timestamp")
    completion_date: Optional[datetime] = Field(default=None, description="Completion timestamp")
    completion_data: Optional[Any] = Field(default=None, description="Completion metadata")
    skill_points_computed: Optional[StrictBool] = Field(default=False, description="Whether skill points have been evaluated")
    resource_id: StrictInt = Field(description="The unique identifier for the resource")
    resource_type: StrictStr = Field(description="The type of resource")
    user_id: StrictInt = Field(description="The user identifier")
    username: StrictStr = Field(description="The username associated with the completion")
    __properties: ClassVar[List[str]] = ["completion_percentage", "completed", "last_updated", "completion_date", "completion_data", "skill_points_computed", "resource_id", "resource_type", "user_id", "username"]

    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 ResourceCompletion 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "last_updated",
            "username",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if completion_percentage (nullable) is None
        # and model_fields_set contains the field
        if self.completion_percentage is None and "completion_percentage" in self.model_fields_set:
            _dict['completion_percentage'] = None

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

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

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

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

        return _dict

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

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "completion_percentage": obj.get("completion_percentage"),
            "completed": obj.get("completed") if obj.get("completed") is not None else False,
            "last_updated": obj.get("last_updated"),
            "completion_date": obj.get("completion_date"),
            "completion_data": obj.get("completion_data"),
            "skill_points_computed": obj.get("skill_points_computed") if obj.get("skill_points_computed") is not None else False,
            "resource_id": obj.get("resource_id"),
            "resource_type": obj.get("resource_type"),
            "user_id": obj.get("user_id"),
            "username": obj.get("username")
        })
        return _obj


