# 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
from typing import Any, ClassVar, Dict, List
from mixpeek.models.failed_object_error import FailedObjectError
from mixpeek.models.object_response import ObjectResponse
from typing import Optional, Set
from typing_extensions import Self

class CreateObjectsBatchResponse(BaseModel):
    """
    Response model for batch object creation with partial success support.  This endpoint uses partial success: valid objects are created even if some fail. Failed objects are tracked separately so users can fix and retry them.
    """ # noqa: E501
    succeeded: List[ObjectResponse] = Field(description="List of successfully created objects")
    failed: List[FailedObjectError] = Field(description="List of objects that failed to create with error details")
    total_requested: StrictInt = Field(description="Total number of objects in the batch request")
    succeeded_count: StrictInt = Field(description="Number of objects successfully created")
    failed_count: StrictInt = Field(description="Number of objects that failed")
    __properties: ClassVar[List[str]] = ["succeeded", "failed", "total_requested", "succeeded_count", "failed_count"]

    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 CreateObjectsBatchResponse 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 succeeded (list)
        _items = []
        if self.succeeded:
            for _item_succeeded in self.succeeded:
                if _item_succeeded:
                    _items.append(_item_succeeded.to_dict())
            _dict['succeeded'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in failed (list)
        _items = []
        if self.failed:
            for _item_failed in self.failed:
                if _item_failed:
                    _items.append(_item_failed.to_dict())
            _dict['failed'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "succeeded": [ObjectResponse.from_dict(_item) for _item in obj["succeeded"]] if obj.get("succeeded") is not None else None,
            "failed": [FailedObjectError.from_dict(_item) for _item in obj["failed"]] if obj.get("failed") is not None else None,
            "total_requested": obj.get("total_requested"),
            "succeeded_count": obj.get("succeeded_count"),
            "failed_count": obj.get("failed_count")
        })
        return _obj


