# coding: utf-8

"""
Root Signals API

Root Signals JSON API provides a way to access Root Signals using provisioned API token

The version of the OpenAPI document: 1.0.0 (latest)
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from datetime import datetime
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing_extensions import Self

from root.generated.openapi_client.models.judge_batch_execution_item import JudgeBatchExecutionItem
from root.generated.openapi_client.models.nested_judge import NestedJudge
from root.generated.openapi_client.models.status776_enum import Status776Enum


class JudgeBatchExecutionDetail(BaseModel):
    """
    JudgeBatchExecutionDetail
    """  # noqa: E501

    batch_execution_id: StrictStr
    status: Status776Enum
    total_count: StrictInt = Field(description="Total number of inputs in the batch")
    completed_count: StrictInt = Field(description="Number of successfully completed executions")
    failed_count: StrictInt = Field(description="Number of failed executions")
    created_at: Optional[datetime]
    started_at: Optional[datetime]
    completed_at: Optional[datetime]
    judge: NestedJudge
    items: List[JudgeBatchExecutionItem]
    __properties: ClassVar[List[str]] = [
        "batch_execution_id",
        "status",
        "total_count",
        "completed_count",
        "failed_count",
        "created_at",
        "started_at",
        "completed_at",
        "judge",
        "items",
    ]

    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 JudgeBatchExecutionDetail 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set(
            [
                "batch_execution_id",
                "status",
                "total_count",
                "completed_count",
                "failed_count",
                "created_at",
                "started_at",
                "completed_at",
                "judge",
                "items",
            ]
        )

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of judge
        if self.judge:
            _dict["judge"] = self.judge.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in items (list)
        _items = []
        if self.items:
            for _item in self.items:
                if _item:
                    _items.append(_item.to_dict())
            _dict["items"] = _items
        # set to None if created_at (nullable) is None
        # and model_fields_set contains the field
        if self.created_at is None and "created_at" in self.model_fields_set:
            _dict["created_at"] = None

        # set to None if started_at (nullable) is None
        # and model_fields_set contains the field
        if self.started_at is None and "started_at" in self.model_fields_set:
            _dict["started_at"] = None

        # set to None if completed_at (nullable) is None
        # and model_fields_set contains the field
        if self.completed_at is None and "completed_at" in self.model_fields_set:
            _dict["completed_at"] = None

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "batch_execution_id": obj.get("batch_execution_id"),
                "status": obj.get("status"),
                "total_count": obj.get("total_count"),
                "completed_count": obj.get("completed_count"),
                "failed_count": obj.get("failed_count"),
                "created_at": obj.get("created_at"),
                "started_at": obj.get("started_at"),
                "completed_at": obj.get("completed_at"),
                "judge": NestedJudge.from_dict(obj["judge"]) if obj.get("judge") is not None else None,
                "items": [JudgeBatchExecutionItem.from_dict(_item) for _item in obj["items"]]
                if obj.get("items") is not None
                else None,
            }
        )
        return _obj
