# 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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.source_filters_input import SourceFiltersInput
from mixpeek.models.source_type import SourceType
from typing import Optional, Set
from typing_extensions import Self

class SourceConfigInput(BaseModel):
    """
    Configuration for collection source (bucket(s) or collection).  Collections can process data from two types of sources:  1. **Bucket Source**: Process raw objects from one or more buckets (first-stage processing)    - Use this to create your initial collections from uploaded data    - Can specify multiple buckets to consolidate data from different sources    - All buckets must have compatible schemas (validated at creation)    - Example: Videos from multiple regions → Frame extraction collection  2. **Collection Source**: Process documents from another collection (decomposition trees)    - Use this to create multi-stage processing pipelines    - Example: Frames collection → Scene detection collection  Multi-Bucket Requirements: - All buckets must have compatible schemas (same fields, types, and required status) - Schema compatibility is validated when the collection is created - Documents track which specific bucket they came from via root_bucket_id - Useful for consolidating data from multiple regions, teams, or environments  The source determines: - What data the feature extractor receives as input - The input_schema available for input_mappings and field_passthrough - The lineage tracking in output documents  Examples:     Single bucket: {\"type\": \"bucket\", \"bucket_ids\": [\"bkt_products\"]}     Multi-bucket: {\"type\": \"bucket\", \"bucket_ids\": [\"bkt_us\", \"bkt_eu\", \"bkt_asia\"]}     Collection: {\"type\": \"collection\", \"collection_id\": \"col_frames\"}
    """ # noqa: E501
    type: SourceType = Field(description="REQUIRED. Type of source for this collection. 'bucket': Process objects from one or more buckets (first-stage processing). 'collection': Process documents from another collection (downstream processing). Use 'bucket' for initial data ingestion, 'collection' for decomposition trees.")
    bucket_ids: Optional[Annotated[List[StrictStr], Field(min_length=1)]] = Field(default=None, description="List of bucket IDs when type='bucket'. REQUIRED when type='bucket'. NOT ALLOWED when type='collection'. Can specify one or more buckets to process. Single bucket: Use array with one element ['bkt_id']. Multiple buckets: All buckets MUST have compatible schemas. Schema compatibility validated at collection creation. Compatible schemas have: 1) Same field names, 2) Same field types, 3) Same required status. Documents will include root_bucket_id to track which bucket they came from. Use cases: multi-region data, multi-team consolidation, environment aggregation.")
    collection_id: Optional[StrictStr] = Field(default=None, description="Collection ID when type='collection' (single collection). Use this OR collection_ids (not both). REQUIRED when type='collection' and processing single collection. NOT ALLOWED when type='bucket'. The collection will process documents from this upstream collection. The upstream collection's output_schema becomes this collection's input_schema. This enables decomposition trees (multi-stage pipelines). Example: Process frames collection → create scenes collection.")
    collection_ids: Optional[Annotated[List[StrictStr], Field(min_length=1)]] = Field(default=None, description="List of collection IDs when type='collection' (multiple collections). Use this OR collection_id (not both). REQUIRED when type='collection' and processing multiple collections. NOT ALLOWED when type='bucket'. Used for operations that consolidate multiple upstream collections. Example: Clustering across multiple collections → cluster output collection. All collections must have compatible schemas for consolidation operations.")
    inherited_bucket_ids: Optional[List[StrictStr]] = Field(default=None, description="List of original bucket IDs that source collections originated from. OPTIONAL. Only used when type='collection'. Tracks the complete lineage chain: buckets → collections → derived collections. Extracted from upstream collection metadata at collection creation time. Enables tracing derived collections (like cluster outputs) back to original data sources. Example: Cluster output collection inherits bucket IDs from its source collections. Format: List of bucket IDs with 'bkt_' prefix.")
    source_filters: Optional[SourceFiltersInput] = Field(default=None, description="Optional filters to apply to source data. When specified, only objects/documents matching these filters will be processed by this collection. Filters are evaluated at batch creation time. Uses same LogicalOperator model as list APIs for consistency.")
    __properties: ClassVar[List[str]] = ["type", "bucket_ids", "collection_id", "collection_ids", "inherited_bucket_ids", "source_filters"]

    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 SourceConfigInput 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_filters
        if self.source_filters:
            _dict['source_filters'] = self.source_filters.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "bucket_ids": obj.get("bucket_ids"),
            "collection_id": obj.get("collection_id"),
            "collection_ids": obj.get("collection_ids"),
            "inherited_bucket_ids": obj.get("inherited_bucket_ids"),
            "source_filters": SourceFiltersInput.from_dict(obj["source_filters"]) if obj.get("source_filters") is not None else None
        })
        return _obj


