# 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
from typing import Any, ClassVar, Dict, List
from mixpeek.models.mappings_value import MappingsValue
from typing import Optional, Set
from typing_extensions import Self

class SchemaMappingInput(BaseModel):
    """
    Complete schema mapping configuration for a sync.  Defines how source data (files, tags, metadata, columns) maps to the target bucket schema. Each key is a target field/blob name in the bucket.  **Key Concepts:** - Keys are target bucket schema field names - Values define the source and extraction method - At least one blob mapping is typically required for file syncs - Field mappings extract metadata alongside the file content  **Provider Examples:**  **S3/Tigris Video Sync:** ```json {     \"content\": {         \"target_type\": \"blob\",         \"source\": {\"type\": \"file\"},         \"blob_type\": \"video\"     },     \"category\": {         \"target_type\": \"field\",         \"source\": {\"type\": \"tag\", \"key\": \"category\"}     },     \"source_bucket\": {         \"target_type\": \"field\",         \"source\": {\"type\": \"constant\", \"value\": \"production-videos\"}     } } ```  **Snowflake Customer Table Sync:** ```json {     \"customer_name\": {         \"target_type\": \"field\",         \"source\": {\"type\": \"column\", \"name\": \"NAME\"}     },     \"profile_image\": {         \"target_type\": \"blob\",         \"source\": {\"type\": \"column\", \"name\": \"AVATAR_URL\"},         \"blob_type\": \"image\"     },     \"segment\": {         \"target_type\": \"field\",         \"source\": {\"type\": \"column\", \"name\": \"CUSTOMER_SEGMENT\"},         \"transform\": \"lowercase\"     } } ```  **Google Drive with Folder Categories:** ```json {     \"content\": {         \"target_type\": \"blob\",         \"source\": {\"type\": \"file\"},         \"blob_type\": \"auto\"     },     \"department\": {         \"target_type\": \"field\",         \"source\": {\"type\": \"folder_path\", \"segment\": 0},         \"transform\": \"lowercase\"     },     \"description\": {         \"target_type\": \"field\",         \"source\": {\"type\": \"drive_property\", \"key\": \"description\"}     } } ```  Attributes:     mappings: Dictionary mapping target field names to their source extractors
    """ # noqa: E501
    mappings: Dict[str, MappingsValue] = Field(description="Dictionary mapping target field names to their source extractors. Keys are bucket schema field names (e.g., 'content', 'category'). Values are mapping entries defining how to extract and store the data. At least one blob mapping (target_type='blob') is recommended for file syncs.")
    __properties: ClassVar[List[str]] = ["mappings"]

    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 SchemaMappingInput 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 each value in mappings (dict)
        _field_dict = {}
        if self.mappings:
            for _key_mappings in self.mappings:
                if self.mappings[_key_mappings]:
                    _field_dict[_key_mappings] = self.mappings[_key_mappings].to_dict()
            _dict['mappings'] = _field_dict
        return _dict

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

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

        _obj = cls.model_validate({
            "mappings": dict(
                (_k, MappingsValue.from_dict(_v))
                for _k, _v in obj["mappings"].items()
            )
            if obj.get("mappings") is not None
            else None
        })
        return _obj


