# 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_extensions import Annotated
from mixpeek.models.export_format import ExportFormat
from mixpeek.models.logical_operator_input import LogicalOperatorInput
from typing import Optional, Set
from typing_extensions import Self

class CollectionExportRequest(BaseModel):
    """
    Request model for exporting collection data.  **Export Formats:** - **JSON**: Line-delimited JSON (JSONL) format, one document per line. Good for streaming and large files. - **CSV**: Comma-separated values. Best for tabular data analysis in spreadsheets. - **PARQUET**: Columnar format optimized for analytics. Best for large datasets and data pipelines.  **Vector Export:** Vectors are stored separately from document metadata due to their large size. When `include_vectors=True`, vectors are exported to a separate file with the naming convention: `{collection_name}_vectors.{format}`  **Field Selection:** Use `select_fields` to export only specific fields, reducing file size for large collections. Supports dot notation for nested fields (e.g., \"metadata.title\").  **Filtering:** Apply filters to export a subset of documents. Uses the same LogicalOperator format as the documents list endpoint.
    """ # noqa: E501
    format: Optional[ExportFormat] = Field(default=None, description="Export format: json (line-delimited), csv, or parquet (default).")
    include_vectors: Optional[StrictBool] = Field(default=False, description="Whether to include vectors in the export. Vectors are exported to a separate file due to their large size. This significantly increases export time and file size.")
    select_fields: Optional[List[StrictStr]] = Field(default=None, description="Specific fields to include in the export. If not provided, all fields are exported. Supports dot notation for nested fields (e.g., 'metadata.title', 'metadata.author').")
    filters: Optional[LogicalOperatorInput] = Field(default=None, description="Filter conditions to export only matching documents. Uses LogicalOperator format (AND/OR/NOT) same as document listing.")
    sample_size: Optional[Annotated[int, Field(le=1000000, strict=True, ge=1)]] = Field(default=None, description="Maximum number of documents to export. If not provided, exports all documents. Useful for testing exports or creating sample datasets.")
    __properties: ClassVar[List[str]] = ["format", "include_vectors", "select_fields", "filters", "sample_size"]

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

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

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

        _obj = cls.model_validate({
            "format": obj.get("format"),
            "include_vectors": obj.get("include_vectors") if obj.get("include_vectors") is not None else False,
            "select_fields": obj.get("select_fields"),
            "filters": LogicalOperatorInput.from_dict(obj["filters"]) if obj.get("filters") is not None else None,
            "sample_size": obj.get("sample_size")
        })
        return _obj


