# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from src.client.generated.models.custom_field_value_with_cf_dto import CustomFieldValueWithCfDto
from src.client.generated.models.external_link_dto import ExternalLinkDto
from src.client.generated.models.issue_dto import IssueDto
from src.client.generated.models.member_dto import MemberDto
from src.client.generated.models.status_dto import StatusDto
from src.client.generated.models.test_case_example_dto import TestCaseExampleDto
from src.client.generated.models.test_case_parameter_dto import TestCaseParameterDto
from src.client.generated.models.test_case_scenario_v2_dto import TestCaseScenarioV2Dto
from src.client.generated.models.test_key_dto import TestKeyDto
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_dto import WorkflowDto
from typing import Optional, Set
from typing_extensions import Self

class TestCaseImportDto(BaseModel):
    """
    TestCaseImportDto
    """ # noqa: E501
    custom_fields: Optional[List[CustomFieldValueWithCfDto]] = Field(default=None, alias="customFields")
    description: Optional[StrictStr] = None
    description_html: Optional[StrictStr] = Field(default=None, alias="descriptionHtml")
    examples: Optional[List[TestCaseExampleDto]] = None
    expected_result: Optional[StrictStr] = Field(default=None, alias="expectedResult")
    expected_result_html: Optional[StrictStr] = Field(default=None, alias="expectedResultHtml")
    full_name: Optional[StrictStr] = Field(default=None, alias="fullName")
    id: Optional[StrictInt] = None
    issues: Optional[List[IssueDto]] = None
    layer: Optional[TestLayerDto] = None
    links: Optional[List[ExternalLinkDto]] = None
    members: Optional[List[MemberDto]] = None
    name: Optional[StrictStr] = None
    parameters: Optional[List[TestCaseParameterDto]] = None
    precondition: Optional[StrictStr] = None
    precondition_html: Optional[StrictStr] = Field(default=None, alias="preconditionHtml")
    project_id: Optional[StrictInt] = Field(default=None, alias="projectId")
    scenario: Optional[TestCaseScenarioV2Dto] = None
    status: Optional[StatusDto] = None
    tags: Optional[List[TestTagDto]] = None
    test_keys: Optional[List[TestKeyDto]] = Field(default=None, alias="testKeys")
    workflow: Optional[WorkflowDto] = None
    __properties: ClassVar[List[str]] = ["customFields", "description", "descriptionHtml", "examples", "expectedResult", "expectedResultHtml", "fullName", "id", "issues", "layer", "links", "members", "name", "parameters", "precondition", "preconditionHtml", "projectId", "scenario", "status", "tags", "testKeys", "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 TestCaseImportDto 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 each item in examples (list)
        _items = []
        if self.examples:
            for _item_examples in self.examples:
                if _item_examples:
                    _items.append(_item_examples.to_dict())
            _dict['examples'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in issues (list)
        _items = []
        if self.issues:
            for _item_issues in self.issues:
                if _item_issues:
                    _items.append(_item_issues.to_dict())
            _dict['issues'] = _items
        # override the default output from pydantic by calling `to_dict()` of layer
        if self.layer:
            _dict['layer'] = self.layer.to_dict()
        # 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 each item in members (list)
        _items = []
        if self.members:
            for _item_members in self.members:
                if _item_members:
                    _items.append(_item_members.to_dict())
            _dict['members'] = _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
        # override the default output from pydantic by calling `to_dict()` of scenario
        if self.scenario:
            _dict['scenario'] = self.scenario.to_dict()
        # 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 each item in test_keys (list)
        _items = []
        if self.test_keys:
            for _item_test_keys in self.test_keys:
                if _item_test_keys:
                    _items.append(_item_test_keys.to_dict())
            _dict['testKeys'] = _items
        # 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 TestCaseImportDto from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "customFields": [CustomFieldValueWithCfDto.from_dict(_item) for _item in obj["customFields"]] if obj.get("customFields") is not None else None,
            "description": obj.get("description"),
            "descriptionHtml": obj.get("descriptionHtml"),
            "examples": [TestCaseExampleDto.from_dict(_item) for _item in obj["examples"]] if obj.get("examples") is not None else None,
            "expectedResult": obj.get("expectedResult"),
            "expectedResultHtml": obj.get("expectedResultHtml"),
            "fullName": obj.get("fullName"),
            "id": obj.get("id"),
            "issues": [IssueDto.from_dict(_item) for _item in obj["issues"]] if obj.get("issues") is not None else None,
            "layer": TestLayerDto.from_dict(obj["layer"]) if obj.get("layer") is not None else None,
            "links": [ExternalLinkDto.from_dict(_item) for _item in obj["links"]] if obj.get("links") is not None else None,
            "members": [MemberDto.from_dict(_item) for _item in obj["members"]] if obj.get("members") is not None else None,
            "name": obj.get("name"),
            "parameters": [TestCaseParameterDto.from_dict(_item) for _item in obj["parameters"]] if obj.get("parameters") is not None else None,
            "precondition": obj.get("precondition"),
            "preconditionHtml": obj.get("preconditionHtml"),
            "projectId": obj.get("projectId"),
            "scenario": TestCaseScenarioV2Dto.from_dict(obj["scenario"]) if obj.get("scenario") is not None else None,
            "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,
            "testKeys": [TestKeyDto.from_dict(_item) for _item in obj["testKeys"]] if obj.get("testKeys") is not None else None,
            "workflow": WorkflowDto.from_dict(obj["workflow"]) if obj.get("workflow") is not None else None
        })
        return _obj


