# 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_extensions import Annotated
from mixpeek.models.blob_type import BlobType
from mixpeek.models.source import Source
from typing import Optional, Set
from typing_extensions import Self

class BlobMappingEntry(BaseModel):
    """
    Maps a source to a blob in the bucket object.  Used for mapping files or URL references to blob fields. The blob_type determines how the content is processed by extractors. This is the primary way to map synced files into the Mixpeek extraction pipeline.  Example: Map the synced file to the primary \"content\" blob     {         \"target_type\": \"blob\",         \"source\": {\"type\": \"file\"},         \"blob_type\": \"auto\",         \"blob_property\": \"content\"     }  Example: Map a database column URL to an image blob     {         \"target_type\": \"blob\",         \"source\": {\"type\": \"column\", \"name\": \"AVATAR_URL\"},         \"blob_type\": \"image\",         \"blob_property\": \"profile_image\"     }  Example: Map with explicit mime_type override     {         \"target_type\": \"blob\",         \"source\": {\"type\": \"file\"},         \"blob_type\": \"video\",         \"blob_property\": \"content\",         \"mime_type_override\": \"video/mp4\"     }  Attributes:     target_type: Must be \"blob\" for blob mappings     source: The source extractor (usually \"file\" for synced content)     blob_type: Content type hint for extractors (auto, image, video, etc.)     blob_property: Name of the blob property in the bucket schema     mime_type_override: Optional explicit mime_type to use
    """ # noqa: E501
    target_type: Optional[StrictStr] = Field(default='blob', description="Target type. Must be 'blob' for blob mappings.")
    source: Source
    blob_type: Optional[BlobType] = Field(default=None, description="Type of blob content. Determines which extractors can process it. 'auto' (default) infers type from mime_type - recommended for files. Explicit types: 'image', 'video', 'audio', 'text', 'document', 'json', 'binary'. Use explicit types when mime_type detection is unreliable.")
    blob_property: Optional[Annotated[str, Field(min_length=1, strict=True)]] = Field(default='content', description="The blob property name in the bucket schema. This identifies which blob in the object's blobs array. Default: 'content' (the primary blob). Must match a blob property defined in the bucket schema.")
    mime_type_override: Optional[StrictStr] = Field(default=None, description="Optional mime_type to use instead of auto-detection. Useful when the source doesn't provide accurate mime_type. Format: 'type/subtype' (e.g., 'image/jpeg', 'video/mp4'). When set, this value is used for blob.details.mime_type.")
    __properties: ClassVar[List[str]] = ["target_type", "source", "blob_type", "blob_property", "mime_type_override"]

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

        if value not in set(['blob']):
            raise ValueError("must be one of enum values ('blob')")
        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 BlobMappingEntry 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 source
        if self.source:
            _dict['source'] = self.source.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "target_type": obj.get("target_type") if obj.get("target_type") is not None else 'blob',
            "source": Source.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "blob_type": obj.get("blob_type"),
            "blob_property": obj.get("blob_property") if obj.get("blob_property") is not None else 'content',
            "mime_type_override": obj.get("mime_type_override")
        })
        return _obj


