# 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, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class AdhocExecutionDetail(BaseModel):
    """
    Detailed information about an ad-hoc retriever execution.  Extends AdhocExecutionSummary with full input data and metadata for comprehensive execution analysis.
    """ # noqa: E501
    execution_id: StrictStr = Field(description="Unique execution identifier.")
    execution_mode: StrictStr = Field(description="Execution mode ('adhoc').")
    status: StrictStr = Field(description="Execution status ('completed', 'failed', etc.).")
    timestamp: Optional[Any]
    duration_ms: Union[Annotated[float, Field(strict=True, ge=0.0)], Annotated[int, Field(strict=True, ge=0)]] = Field(description="Total execution duration in milliseconds.")
    credits_used: Union[Annotated[float, Field(strict=True, ge=0.0)], Annotated[int, Field(strict=True, ge=0)]] = Field(description="Credits consumed during execution.")
    total_processed: Annotated[int, Field(strict=True, ge=0)] = Field(description="Total documents processed across all stages.")
    total_returned: Annotated[int, Field(strict=True, ge=0)] = Field(description="Number of documents returned in final results.")
    cache_hit_rate: Optional[Union[Annotated[float, Field(le=1.0, strict=True, ge=0.0)], Annotated[int, Field(le=1, strict=True, ge=0)]]] = Field(default=None, description="Cache hit rate across stages (0.0-1.0).")
    query_summary: Optional[StrictStr] = Field(default=None, description="Brief summary of the query inputs.")
    stages_completed: Annotated[int, Field(strict=True, ge=0)] = Field(description="Number of stages completed.")
    total_stages: Annotated[int, Field(strict=True, ge=0)] = Field(description="Total number of stages in the pipeline.")
    collection_ids: Optional[List[StrictStr]] = Field(default=None, description="Collections queried during execution.")
    inputs: Optional[StrictStr] = Field(default=None, description="Full input data provided for execution.")
    inputs_hash: Optional[StrictStr] = Field(default=None, description="SHA-1 hash of inputs for deduplication.")
    __properties: ClassVar[List[str]] = ["execution_id", "execution_mode", "status", "timestamp", "duration_ms", "credits_used", "total_processed", "total_returned", "cache_hit_rate", "query_summary", "stages_completed", "total_stages", "collection_ids", "inputs", "inputs_hash"]

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

        return _dict

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

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

        _obj = cls.model_validate({
            "execution_id": obj.get("execution_id"),
            "execution_mode": obj.get("execution_mode"),
            "status": obj.get("status"),
            "timestamp": obj.get("timestamp"),
            "duration_ms": obj.get("duration_ms"),
            "credits_used": obj.get("credits_used"),
            "total_processed": obj.get("total_processed"),
            "total_returned": obj.get("total_returned"),
            "cache_hit_rate": obj.get("cache_hit_rate"),
            "query_summary": obj.get("query_summary"),
            "stages_completed": obj.get("stages_completed"),
            "total_stages": obj.get("total_stages"),
            "collection_ids": obj.get("collection_ids"),
            "inputs": obj.get("inputs"),
            "inputs_hash": obj.get("inputs_hash")
        })
        return _obj


