# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class InternalLineageModel(BaseModel):
    """
    Lineage tracking information for document provenance.  Tracks the complete processing history from the original bucket object through all transformation stages in the decomposition tree.
    """ # noqa: E501
    root_object_id: Optional[StrictStr] = Field(default=None, description="Original object ID from bucket (root of decomposition tree). All documents derived from the same object share this ID.")
    root_bucket_id: Optional[StrictStr] = Field(default=None, description="Bucket ID containing the root object.")
    source_type: Optional[StrictStr] = Field(default=None, description="Type of immediate parent source. 'bucket': Document created directly from bucket object (tier 1). 'collection': Document created from another collection (tier 2+).")
    source_object_id: Optional[StrictStr] = Field(default=None, description="Object ID of immediate parent when source_type='bucket'.")
    source_document_id: Optional[StrictStr] = Field(default=None, description="Document ID of immediate parent when source_type='collection'.")
    source_collection_id: Optional[StrictStr] = Field(default=None, description="Collection ID of immediate parent when source_type='collection'.")
    path: Optional[StrictStr] = Field(default=None, description="Materialized lineage path string (e.g., 'bkt_123/col_456/col_789').")
    chain: Optional[List[Dict[str, Any]]] = Field(default=None, description="Ordered list of processing steps from root object to this document. Each step contains: collection_id, feature_extractor_id, document_id, timestamp.")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["root_object_id", "root_bucket_id", "source_type", "source_object_id", "source_document_id", "source_collection_id", "path", "chain"]

    @field_validator('source_type')
    def source_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['bucket', 'collection']):
            raise ValueError("must be one of enum values ('bucket', 'collection')")
        return value

    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 InternalLineageModel 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,
        )
        # 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 InternalLineageModel from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "root_object_id": obj.get("root_object_id"),
            "root_bucket_id": obj.get("root_bucket_id"),
            "source_type": obj.get("source_type"),
            "source_object_id": obj.get("source_object_id"),
            "source_document_id": obj.get("source_document_id"),
            "source_collection_id": obj.get("source_collection_id"),
            "path": obj.get("path"),
            "chain": obj.get("chain")
        })
        # 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


