# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.update_test_run_custom_fields_inner import UpdateTestRunCustomFieldsInner
from openapi_client.models.xray_json_import_execution_tests_inner_evidences_inner import XrayJsonImportExecutionTestsInnerEvidencesInner
from openapi_client.models.xray_json_import_execution_tests_inner_results_inner import XrayJsonImportExecutionTestsInnerResultsInner
from openapi_client.models.xray_json_import_execution_tests_inner_steps_inner import XrayJsonImportExecutionTestsInnerStepsInner
from openapi_client.models.xray_json_import_execution_tests_inner_test_info import XrayJsonImportExecutionTestsInnerTestInfo
from typing import Optional, Set
from typing_extensions import Self

class XrayJsonImportExecutionTestsInner(BaseModel):
    """
    XrayJsonImportExecutionTestsInner
    """ # noqa: E501
    comment: Optional[StrictStr] = None
    finish: Optional[StrictStr] = None
    start: Optional[StrictStr] = None
    status: Optional[StrictStr] = None
    test_version: Optional[StrictStr] = Field(default=None, alias="testVersion")
    custom_fields: Optional[List[UpdateTestRunCustomFieldsInner]] = Field(default=None, alias="customFields")
    test_info: Optional[XrayJsonImportExecutionTestsInnerTestInfo] = Field(default=None, alias="testInfo")
    test_key: Optional[StrictStr] = Field(default=None, alias="testKey")
    executed_by: Optional[StrictStr] = Field(default=None, alias="executedBy")
    evidences: Optional[List[XrayJsonImportExecutionTestsInnerEvidencesInner]] = None
    results: Optional[List[XrayJsonImportExecutionTestsInnerResultsInner]] = None
    examples: Optional[List[StrictStr]] = None
    steps: Optional[List[XrayJsonImportExecutionTestsInnerStepsInner]] = None
    __properties: ClassVar[List[str]] = ["comment", "finish", "start", "status", "testVersion", "customFields", "testInfo", "testKey", "executedBy", "evidences", "results", "examples", "steps"]

    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 XrayJsonImportExecutionTestsInner 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 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 test_info
        if self.test_info:
            _dict['testInfo'] = self.test_info.to_dict()
        # 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 results (list)
        _items = []
        if self.results:
            for _item_results in self.results:
                if _item_results:
                    _items.append(_item_results.to_dict())
            _dict['results'] = _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
        return _dict

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

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

        _obj = cls.model_validate({
            "comment": obj.get("comment"),
            "finish": obj.get("finish"),
            "start": obj.get("start"),
            "status": obj.get("status"),
            "testVersion": obj.get("testVersion"),
            "customFields": [UpdateTestRunCustomFieldsInner.from_dict(_item) for _item in obj["customFields"]] if obj.get("customFields") is not None else None,
            "testInfo": XrayJsonImportExecutionTestsInnerTestInfo.from_dict(obj["testInfo"]) if obj.get("testInfo") is not None else None,
            "testKey": obj.get("testKey"),
            "executedBy": obj.get("executedBy"),
            "evidences": [XrayJsonImportExecutionTestsInnerEvidencesInner.from_dict(_item) for _item in obj["evidences"]] if obj.get("evidences") is not None else None,
            "results": [XrayJsonImportExecutionTestsInnerResultsInner.from_dict(_item) for _item in obj["results"]] if obj.get("results") is not None else None,
            "examples": obj.get("examples"),
            "steps": [XrayJsonImportExecutionTestsInnerStepsInner.from_dict(_item) for _item in obj["steps"]] if obj.get("steps") is not None else None
        })
        return _obj


