# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from mixpeek.models.batch_error_detail import BatchErrorDetail
from mixpeek.models.task_status_enum import TaskStatusEnum
from typing import Optional, Set
from typing_extensions import Self

class ExtractorJobInfo(BaseModel):
    """
    Tracking information for a single feature extractor job within a tier.  Each tier can have multiple extractor jobs running in parallel, one per unique feature_extractor_type. This allows different extractors to have independent: - Resource requirements (GPUs, CPU, memory) - Status tracking and retry logic - Ray job IDs and Celery task IDs - Completion times and performance metrics  Example:     Tier 1 with collections using different extractors:     - col_A: image_extractor     - col_B: face_identity_extractor     - col_C: image_extractor      Creates 2 ExtractorJobInfo instances:     1. extractor_type=\"image_extractor\", collection_ids=[\"col_A\", \"col_C\"]     2. extractor_type=\"face_identity_extractor\", collection_ids=[\"col_B\"]  Lifecycle:     1. Created with status=PENDING when tier is scheduled     2. Updated to IN_PROGRESS when Ray job starts     3. Finalized to COMPLETED/FAILED when Ray job completes
    """ # noqa: E501
    extractor_type: StrictStr = Field(description="Feature extractor type (e.g., 'image_extractor', 'face_identity_extractor')")
    collection_ids: Optional[Annotated[List[StrictStr], Field(min_length=1)]] = Field(default=None, description="Collections processed by this extractor job")
    ray_job_id: Optional[StrictStr] = Field(default=None, description="Ray job ID for this extractor job")
    celery_task_id: Optional[StrictStr] = Field(default=None, description="Celery task ID that submitted this Ray job")
    status: Optional[TaskStatusEnum] = Field(default=None, description="Current status of this extractor job")
    started_at: Optional[datetime] = Field(default=None, description="When this extractor job started processing")
    completed_at: Optional[datetime] = Field(default=None, description="When this extractor job finished processing")
    duration_ms: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Processing duration in milliseconds")
    documents_written: Optional[StrictInt] = Field(default=None, description="Number of documents written by this extractor job")
    errors: Optional[List[BatchErrorDetail]] = Field(default=None, description="Detailed errors from this extractor job")
    error: Optional[StrictStr] = Field(default=None, description="OPTIONAL. Simple error message string for quick debugging. Set when the Ray job fails with error details from JobStatusMonitor. For detailed error information, see errors array.")
    __properties: ClassVar[List[str]] = ["extractor_type", "collection_ids", "ray_job_id", "celery_task_id", "status", "started_at", "completed_at", "duration_ms", "documents_written", "errors", "error"]

    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 ExtractorJobInfo 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 item in errors (list)
        _items = []
        if self.errors:
            for _item_errors in self.errors:
                if _item_errors:
                    _items.append(_item_errors.to_dict())
            _dict['errors'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "extractor_type": obj.get("extractor_type"),
            "collection_ids": obj.get("collection_ids"),
            "ray_job_id": obj.get("ray_job_id"),
            "celery_task_id": obj.get("celery_task_id"),
            "status": obj.get("status"),
            "started_at": obj.get("started_at"),
            "completed_at": obj.get("completed_at"),
            "duration_ms": obj.get("duration_ms"),
            "documents_written": obj.get("documents_written"),
            "errors": [BatchErrorDetail.from_dict(_item) for _item in obj["errors"]] if obj.get("errors") is not None else None,
            "error": obj.get("error")
        })
        return _obj


