
"""
    Aignostics Platform API reference

     Pagination is done via `page` and `page_size`. Sorting via `sort` query parameter. The `sort` query parameter can be provided multiple times. The sorting direction can be indicated via `+` (ascending) or `-` (descending) (e.g. `/v1/applications?sort=+name)`.

    The version of the OpenAPI document: 1.0.0
    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
from aignx.codegen.models.item_status import ItemStatus
from aignx.codegen.models.output_artifact_result_read_response import OutputArtifactResultReadResponse
from typing import Optional, Set
from typing_extensions import Self

class ItemResultReadResponse(BaseModel):
    """
    ItemResultReadResponse
    """ # noqa: E501
    item_id: StrictStr = Field(description="Item UUID generated by the Platform")
    application_run_id: StrictStr = Field(description="Application run UUID to which the item belongs")
    reference: StrictStr = Field(description="The reference of the item from the user payload")
    status: ItemStatus = Field(description=" When the item is not processed yet, the status is set to `pending`.  When the item is successfully finished, status is set to `succeeded`, and the processing results become available for download in `output_artifacts` field.  When the item processing is failed because the provided item is invalid, the status is set to `error_user`. When the item processing failed because of the error in the model or platform, the status is set to `error_system`. When the application_run is canceled, the status of all pending items is set to either `cancelled_user` or `cancelled_system`.     ")
    error: Optional[StrictStr]
    output_artifacts: List[OutputArtifactResultReadResponse] = Field(description=" The list of the results generated by the application algorithm. The number of files and their types depend on the particular application version, call `/v1/versions/{version_id}` to get the details.     ")
    __properties: ClassVar[List[str]] = ["item_id", "application_run_id", "reference", "status", "error", "output_artifacts"]

    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 ItemResultReadResponse 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 output_artifacts (list)
        _items = []
        if self.output_artifacts:
            for _item_output_artifacts in self.output_artifacts:
                if _item_output_artifacts:
                    _items.append(_item_output_artifacts.to_dict())
            _dict['output_artifacts'] = _items
        # set to None if error (nullable) is None
        # and model_fields_set contains the field
        if self.error is None and "error" in self.model_fields_set:
            _dict['error'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "item_id": obj.get("item_id"),
            "application_run_id": obj.get("application_run_id"),
            "reference": obj.get("reference"),
            "status": obj.get("status"),
            "error": obj.get("error"),
            "output_artifacts": [OutputArtifactResultReadResponse.from_dict(_item) for _item in obj["output_artifacts"]] if obj.get("output_artifacts") is not None else None
        })
        return _obj
