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

class RetryBatchRequest(BaseModel):
    """
    Request to retry failed documents in a batch.  Allows selective retry of failed documents with intelligent filtering by error type and tier. Retries use exponential backoff and respect max retry limits.  Use Cases:     - Retry only transient errors after resolving temporary infrastructure issues     - Retry specific processing tiers that failed     - Retry all failed documents regardless of error type (force retry)  Requirements:     - retry_mode: REQUIRED. Determines which documents to retry     - tier_nums: OPTIONAL. Only retry failures from specific tiers (empty = all tiers)     - max_retry_count: OPTIONAL. Skip documents that have been retried this many times  Behavior:     - 'transient_only': Retries only transient errors (network, timeout, rate limit)     - 'all': Retries both transient and permanent errors     - Documents beyond max_retry_count are excluded from retry     - Each retry increments the document's retry_count
    """ # noqa: E501
    retry_mode: Optional[StrictStr] = Field(default='transient_only', description="Determines which types of failed documents to retry. 'transient_only': Only retry documents that failed with transient errors (network issues, timeouts, rate limits). This is the recommended default as it avoids retrying documents with permanent failures (invalid data, missing fields, incompatible formats). 'all': Retry all failed documents regardless of error type. Use this for force retries after fixing data issues or updating extraction logic.")
    tier_nums: Optional[List[StrictInt]] = Field(default=None, description="List of specific tier numbers to retry failures from. OPTIONAL - If not provided or empty list, retries failures from all tiers. Use this to selectively retry a specific processing stage. Example: [2] would only retry failures from tier 2 (the third processing stage). Tier numbering starts at 0 (bucket → collection), tier 1+ are collection → collection.")
    max_retry_count: Optional[Annotated[int, Field(le=10, strict=True, ge=1)]] = Field(default=3, description="Maximum number of times a document can be retried. Documents that have been retried this many times already are excluded. Prevents infinite retry loops for documents with persistent issues. Default is 3 retries per document. Set to higher value for more aggressive retries.")
    __properties: ClassVar[List[str]] = ["retry_mode", "tier_nums", "max_retry_count"]

    @field_validator('retry_mode')
    def retry_mode_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['transient_only', 'all']):
            raise ValueError("must be one of enum values ('transient_only', 'all')")
        return value

    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 RetryBatchRequest 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "retry_mode": obj.get("retry_mode") if obj.get("retry_mode") is not None else 'transient_only',
            "tier_nums": obj.get("tier_nums"),
            "max_retry_count": obj.get("max_retry_count") if obj.get("max_retry_count") is not None else 3
        })
        return _obj


