# coding: utf-8

"""
    Xray REST API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 2.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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.dataset_parameter import DatasetParameter
from openapi_client.models.file_response import FileResponse
from openapi_client.models.step_result import StepResult
from openapi_client.models.test_run_iteration_status_information import TestRunIterationStatusInformation
from openapi_client.models.test_run_response_custom_fields_inner import TestRunResponseCustomFieldsInner
from openapi_client.models.version import Version
from typing import Optional, Set
from typing_extensions import Self

class TestRunResponse(BaseModel):
    """
    TestRunResponse
    """ # noqa: E501
    id: Optional[StrictInt] = None
    status: Optional[StrictStr] = None
    color: Optional[StrictStr] = None
    test_key: Optional[StrictStr] = Field(default=None, alias="testKey")
    test_exec_key: Optional[StrictStr] = Field(default=None, alias="testExecKey")
    test_version: Optional[StrictStr] = Field(default=None, alias="testVersion")
    assignee: Optional[StrictStr] = None
    executed_by: Optional[StrictStr] = Field(default=None, alias="executedBy")
    started_on: Optional[StrictStr] = Field(default=None, alias="startedOn")
    finished_on: Optional[StrictStr] = Field(default=None, alias="finishedOn")
    started_on_iso: Optional[StrictStr] = Field(default=None, alias="startedOnIso")
    finished_on_iso: Optional[StrictStr] = Field(default=None, alias="finishedOnIso")
    duration: Optional[StrictInt] = None
    defects: Optional[List[StrictStr]] = None
    evidences: Optional[List[FileResponse]] = None
    comment: Optional[StrictStr] = None
    test_environments: Optional[List[StrictStr]] = Field(default=None, alias="testEnvironments")
    fix_versions: Optional[List[Version]] = Field(default=None, alias="fixVersions")
    custom_fields: Optional[List[TestRunResponseCustomFieldsInner]] = Field(default=None, alias="customFields")
    steps: Optional[List[StepResult]] = None
    iterations: Optional[List[TestRunIterationStatusInformation]] = None
    parameters: Optional[List[DatasetParameter]] = None
    __properties: ClassVar[List[str]] = ["id", "status", "color", "testKey", "testExecKey", "testVersion", "assignee", "executedBy", "startedOn", "finishedOn", "startedOnIso", "finishedOnIso", "duration", "defects", "evidences", "comment", "testEnvironments", "fixVersions", "customFields", "steps", "iterations", "parameters"]

    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 TestRunResponse 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 evidences (list)
        _items = []
        if self.evidences:
            for _item_evidences in self.evidences:
                if _item_evidences:
                    _items.append(_item_evidences.to_dict())
            _dict['evidences'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in fix_versions (list)
        _items = []
        if self.fix_versions:
            for _item_fix_versions in self.fix_versions:
                if _item_fix_versions:
                    _items.append(_item_fix_versions.to_dict())
            _dict['fixVersions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in custom_fields (list)
        _items = []
        if self.custom_fields:
            for _item_custom_fields in self.custom_fields:
                if _item_custom_fields:
                    _items.append(_item_custom_fields.to_dict())
            _dict['customFields'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in steps (list)
        _items = []
        if self.steps:
            for _item_steps in self.steps:
                if _item_steps:
                    _items.append(_item_steps.to_dict())
            _dict['steps'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in iterations (list)
        _items = []
        if self.iterations:
            for _item_iterations in self.iterations:
                if _item_iterations:
                    _items.append(_item_iterations.to_dict())
            _dict['iterations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in parameters (list)
        _items = []
        if self.parameters:
            for _item_parameters in self.parameters:
                if _item_parameters:
                    _items.append(_item_parameters.to_dict())
            _dict['parameters'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "status": obj.get("status"),
            "color": obj.get("color"),
            "testKey": obj.get("testKey"),
            "testExecKey": obj.get("testExecKey"),
            "testVersion": obj.get("testVersion"),
            "assignee": obj.get("assignee"),
            "executedBy": obj.get("executedBy"),
            "startedOn": obj.get("startedOn"),
            "finishedOn": obj.get("finishedOn"),
            "startedOnIso": obj.get("startedOnIso"),
            "finishedOnIso": obj.get("finishedOnIso"),
            "duration": obj.get("duration"),
            "defects": obj.get("defects"),
            "evidences": [FileResponse.from_dict(_item) for _item in obj["evidences"]] if obj.get("evidences") is not None else None,
            "comment": obj.get("comment"),
            "testEnvironments": obj.get("testEnvironments"),
            "fixVersions": [Version.from_dict(_item) for _item in obj["fixVersions"]] if obj.get("fixVersions") is not None else None,
            "customFields": [TestRunResponseCustomFieldsInner.from_dict(_item) for _item in obj["customFields"]] if obj.get("customFields") is not None else None,
            "steps": [StepResult.from_dict(_item) for _item in obj["steps"]] if obj.get("steps") is not None else None,
            "iterations": [TestRunIterationStatusInformation.from_dict(_item) for _item in obj["iterations"]] if obj.get("iterations") is not None else None,
            "parameters": [DatasetParameter.from_dict(_item) for _item in obj["parameters"]] if obj.get("parameters") is not None else None
        })
        return _obj


