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

class FieldPassthrough(BaseModel):
    """
    Configuration for passing fields from source to output documents.  Simple field passthrough: specify which fields to copy from source (bucket object or upstream collection document) to the output documents alongside extractor outputs.  Use Cases:     - Preserve identifiers: campaign_id, product_sku, user_id     - Keep metadata: category, tags, author, timestamp     - Maintain business context: priority, status, region     - Extract nested values: metadata.author, config.model_version     - Rename fields for cleaner schemas: doc_title → title  Field Selection:     - WITHOUT field_passthrough: Only extractor outputs appear in documents     - WITH field_passthrough: Specified fields + extractor outputs     - WITH include_all_source_fields=True: All source fields + extractor outputs  Field Naming:     - WITHOUT target_path: Output uses source name (or last component for nested)       - \"title\" → \"title\"       - \"metadata.author\" → \"author\"     - WITH target_path: Output uses specified name       - source_path=\"doc_title\", target_path=\"title\" → \"title\"       - source_path=\"metadata.author\", target_path=\"contributor\" → \"contributor\"  Requirements:     - source_path is REQUIRED - specifies which field to copy (supports dot notation)     - target_path is OPTIONAL - rename field in output (default: auto-derived name)     - default is OPTIONAL - provides fallback if field missing (default: omit field)     - required is OPTIONAL - errors if field missing (default: false, omit field)
    """ # noqa: E501
    source_path: StrictStr = Field(description="REQUIRED. Path to the source field to copy. Simple fields: Use field name directly (e.g., 'title', 'campaign_id'). Nested fields: Use dot notation (e.g., 'metadata.author', 'config.model.version'). The field must exist in the source bucket schema or upstream collection schema. Without target_path, nested fields are flattened: 'metadata.author' becomes 'author' in output.")
    target_path: Optional[StrictStr] = Field(default=None, description="OPTIONAL. Target field name in output document. If NOT PROVIDED: Uses source_path name (or last component for nested paths).   - 'title' → 'title'   - 'metadata.author' → 'author' If PROVIDED: Uses this exact name in output.   - source_path='doc_title', target_path='title' → 'title'   - source_path='metadata.author', target_path='contributor' → 'contributor' Use cases:   - Rename fields for cleaner API schemas   - Avoid name conflicts with extractor outputs   - Standardize field names across different sources Constraints:   - Must not conflict with system fields (document_id, collection_id, etc.)   - Must not conflict with extractor output fields   - Must be a valid field name (alphanumeric, underscores, hyphens)")
    default: Optional[Any] = None
    required: Optional[StrictBool] = Field(default=False, description="OPTIONAL. Whether this field MUST exist in source. If True and field missing: Raises validation error, processing fails. If False and field missing: Field omitted (or default used if provided). Use True for: Critical identifiers, required business fields. Use False for: Optional metadata, nice-to-have fields. Default: False (field is optional).")
    __properties: ClassVar[List[str]] = ["source_path", "target_path", "default", "required"]

    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 FieldPassthrough 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,
        )
        # set to None if default (nullable) is None
        # and model_fields_set contains the field
        if self.default is None and "default" in self.model_fields_set:
            _dict['default'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "source_path": obj.get("source_path"),
            "target_path": obj.get("target_path"),
            "default": obj.get("default"),
            "required": obj.get("required") if obj.get("required") is not None else False
        })
        return _obj


