# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 4.202.1-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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from uuid import UUID
from iblai.models.artifact import Artifact
from iblai.models.interface_enum import InterfaceEnum
from typing import Optional, Set
from typing_extensions import Self

class ArtifactVersion(BaseModel):
    """
    Serializer for ArtifactVersion model.  Represents a single version of an artifact with its content and metadata.
    """ # noqa: E501
    id: StrictInt
    artifact: Artifact
    title: StrictStr = Field(description="Get the title of the artifact version.")
    content: StrictStr = Field(description="The markdown-styled content of this artifact version")
    session_id: UUID = Field(description="UUID of the session that generated this artifact version")
    content_length: StrictInt = Field(description="Length of the version content in characters")
    is_current: StrictBool = Field(description="Whether this version is the current/active version")
    chat_message: Optional[StrictInt]
    version_number: StrictInt = Field(description="Sequential version number for display purposes")
    date_created: datetime = Field(description="When this version was created")
    created_by: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="Identifier for who created this version (e.g., 'llm', 'user:username')")
    change_summary: Optional[Annotated[str, Field(strict=True, max_length=500)]] = Field(default=None, description="Optional summary of what changed in this version")
    interface: InterfaceEnum = Field(description="How this version was created  * `chat` - Chat * `api` - Api")
    __properties: ClassVar[List[str]] = ["id", "artifact", "title", "content", "session_id", "content_length", "is_current", "chat_message", "version_number", "date_created", "created_by", "change_summary", "interface"]

    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 ArtifactVersion 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "title",
            "session_id",
            "content_length",
            "is_current",
            "chat_message",
            "version_number",
            "date_created",
            "interface",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of artifact
        if self.artifact:
            _dict['artifact'] = self.artifact.to_dict()
        # set to None if chat_message (nullable) is None
        # and model_fields_set contains the field
        if self.chat_message is None and "chat_message" in self.model_fields_set:
            _dict['chat_message'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "artifact": Artifact.from_dict(obj["artifact"]) if obj.get("artifact") is not None else None,
            "title": obj.get("title"),
            "content": obj.get("content"),
            "session_id": obj.get("session_id"),
            "content_length": obj.get("content_length"),
            "is_current": obj.get("is_current"),
            "chat_message": obj.get("chat_message"),
            "version_number": obj.get("version_number") if obj.get("version_number") is not None else 1,
            "date_created": obj.get("date_created"),
            "created_by": obj.get("created_by"),
            "change_summary": obj.get("change_summary"),
            "interface": obj.get("interface")
        })
        return _obj


