# coding: utf-8

"""
    allure-testops-service

    Branch **HEAD**  Commit **623f6ed302ba4b651cf9040faca4635af2d93b7c**

    The version of the OpenAPI document: 25.4.1
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from src.client.generated.models.external_link_dto import ExternalLinkDto
from src.client.generated.models.status_dto import StatusDto
from src.client.generated.models.test_layer_dto import TestLayerDto
from src.client.generated.models.test_tag_dto import TestTagDto
from src.client.generated.models.workflow_row_dto import WorkflowRowDto
from typing import Optional, Set
from typing_extensions import Self

class TestCaseDto(BaseModel):
    """
    TestCaseDto
    """ # noqa: E501
    automated: Optional[StrictBool] = None
    created_by: Optional[StrictStr] = Field(default=None, alias="createdBy")
    created_date: Optional[StrictInt] = Field(default=None, alias="createdDate")
    deleted: Optional[StrictBool] = None
    description: Optional[StrictStr] = None
    description_html: Optional[StrictStr] = Field(default=None, alias="descriptionHtml")
    editable: Optional[StrictBool] = None
    expected_result: Optional[StrictStr] = Field(default=None, alias="expectedResult")
    expected_result_html: Optional[StrictStr] = Field(default=None, alias="expectedResultHtml")
    external: Optional[StrictBool] = None
    full_name: Optional[StrictStr] = Field(default=None, alias="fullName")
    hash: Optional[StrictStr] = None
    id: Optional[StrictInt] = None
    last_modified_by: Optional[StrictStr] = Field(default=None, alias="lastModifiedBy")
    last_modified_date: Optional[StrictInt] = Field(default=None, alias="lastModifiedDate")
    links: Optional[List[ExternalLinkDto]] = None
    name: Optional[StrictStr] = None
    precondition: Optional[StrictStr] = None
    precondition_html: Optional[StrictStr] = Field(default=None, alias="preconditionHtml")
    project_id: Optional[StrictInt] = Field(default=None, alias="projectId")
    status: Optional[StatusDto] = None
    tags: Optional[List[TestTagDto]] = None
    test_layer: Optional[TestLayerDto] = Field(default=None, alias="testLayer")
    workflow: Optional[WorkflowRowDto] = None
    __properties: ClassVar[List[str]] = ["automated", "createdBy", "createdDate", "deleted", "description", "descriptionHtml", "editable", "expectedResult", "expectedResultHtml", "external", "fullName", "hash", "id", "lastModifiedBy", "lastModifiedDate", "links", "name", "precondition", "preconditionHtml", "projectId", "status", "tags", "testLayer", "workflow"]

    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 TestCaseDto 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 links (list)
        _items = []
        if self.links:
            for _item_links in self.links:
                if _item_links:
                    _items.append(_item_links.to_dict())
            _dict['links'] = _items
        # override the default output from pydantic by calling `to_dict()` of status
        if self.status:
            _dict['status'] = self.status.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict['tags'] = _items
        # override the default output from pydantic by calling `to_dict()` of test_layer
        if self.test_layer:
            _dict['testLayer'] = self.test_layer.to_dict()
        # override the default output from pydantic by calling `to_dict()` of workflow
        if self.workflow:
            _dict['workflow'] = self.workflow.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "automated": obj.get("automated"),
            "createdBy": obj.get("createdBy"),
            "createdDate": obj.get("createdDate"),
            "deleted": obj.get("deleted"),
            "description": obj.get("description"),
            "descriptionHtml": obj.get("descriptionHtml"),
            "editable": obj.get("editable"),
            "expectedResult": obj.get("expectedResult"),
            "expectedResultHtml": obj.get("expectedResultHtml"),
            "external": obj.get("external"),
            "fullName": obj.get("fullName"),
            "hash": obj.get("hash"),
            "id": obj.get("id"),
            "lastModifiedBy": obj.get("lastModifiedBy"),
            "lastModifiedDate": obj.get("lastModifiedDate"),
            "links": [ExternalLinkDto.from_dict(_item) for _item in obj["links"]] if obj.get("links") is not None else None,
            "name": obj.get("name"),
            "precondition": obj.get("precondition"),
            "preconditionHtml": obj.get("preconditionHtml"),
            "projectId": obj.get("projectId"),
            "status": StatusDto.from_dict(obj["status"]) if obj.get("status") is not None else None,
            "tags": [TestTagDto.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "testLayer": TestLayerDto.from_dict(obj["testLayer"]) if obj.get("testLayer") is not None else None,
            "workflow": WorkflowRowDto.from_dict(obj["workflow"]) if obj.get("workflow") is not None else None
        })
        return _obj


