# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    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 mixpeek.models.internal_lineage_model import InternalLineageModel
from mixpeek.models.internal_processing_model import InternalProcessingModel
from typing import Optional, Set
from typing_extensions import Self

class InternalPayloadModel(BaseModel):
    """
    Complete _internal field structure for Qdrant document payloads.  All Mixpeek-managed system fields are namespaced under this structure to: - Prevent collision with user-defined fields - Provide clear separation of system vs user data - Enable filtering on internal fields via _internal.field_name paths  This structure is stored in Qdrant and returned in API responses.
    """ # noqa: E501
    internal_id: Optional[StrictStr] = Field(default=None, description="Organization/tenant identifier for multi-tenancy isolation.")
    namespace_id: Optional[StrictStr] = Field(default=None, description="Namespace identifier within the organization.")
    document_id: Optional[StrictStr] = Field(default=None, description="Document identifier (also at root level for convenience).")
    collection_id: Optional[StrictStr] = Field(default=None, description="Collection identifier (also at root level for convenience).")
    created_at: Optional[StrictStr] = Field(default=None, description="ISO 8601 timestamp when document was created.")
    updated_at: Optional[StrictStr] = Field(default=None, description="ISO 8601 timestamp when document was last updated.")
    lineage: Optional[InternalLineageModel] = Field(default=None, description="Document lineage and provenance tracking.")
    processing: Optional[InternalProcessingModel] = Field(default=None, description="Processing history and provenance metadata.")
    source_blobs: Optional[List[Dict[str, Any]]] = Field(default=None, description="Blobs that constituted the original source object.")
    document_blobs: Optional[List[Dict[str, Any]]] = Field(default=None, description="Blobs generated during document processing (thumbnails, etc.).")
    source_details: Optional[List[Dict[str, Any]]] = Field(default=None, description="Enrichment tracking and source detail entries.")
    modality: Optional[StrictStr] = Field(default=None, description="Content modality (text, image, video, audio, etc.).")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="System metadata including ingestion_status, feature_extractor_config_hash, and other processing-related information.")
    mime_type: Optional[StrictStr] = Field(default=None, description="MIME type of the source content.")
    size_bytes: Optional[StrictInt] = Field(default=None, description="Size of the source content in bytes.")
    content_hash: Optional[StrictStr] = Field(default=None, description="SHA256 hash of the source content for deduplication.")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["internal_id", "namespace_id", "document_id", "collection_id", "created_at", "updated_at", "lineage", "processing", "source_blobs", "document_blobs", "source_details", "modality", "metadata", "mime_type", "size_bytes", "content_hash"]

    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 InternalPayloadModel 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of lineage
        if self.lineage:
            _dict['lineage'] = self.lineage.to_dict()
        # override the default output from pydantic by calling `to_dict()` of processing
        if self.processing:
            _dict['processing'] = self.processing.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

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

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

        _obj = cls.model_validate({
            "internal_id": obj.get("internal_id"),
            "namespace_id": obj.get("namespace_id"),
            "document_id": obj.get("document_id"),
            "collection_id": obj.get("collection_id"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "lineage": InternalLineageModel.from_dict(obj["lineage"]) if obj.get("lineage") is not None else None,
            "processing": InternalProcessingModel.from_dict(obj["processing"]) if obj.get("processing") is not None else None,
            "source_blobs": obj.get("source_blobs"),
            "document_blobs": obj.get("document_blobs"),
            "source_details": obj.get("source_details"),
            "modality": obj.get("modality"),
            "metadata": obj.get("metadata"),
            "mime_type": obj.get("mime_type"),
            "size_bytes": obj.get("size_bytes"),
            "content_hash": obj.get("content_hash")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


