# 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.custom_field_value_with_cf_dto import CustomFieldValueWithCfDto
from src.client.generated.models.external_link_dto import ExternalLinkDto
from src.client.generated.models.member_dto import MemberDto
from src.client.generated.models.test_case_scenario_v2_dto import TestCaseScenarioV2Dto
from src.client.generated.models.test_tag_dto import TestTagDto
from typing import Optional, Set
from typing_extensions import Self

class TestCasePatchV2Dto(BaseModel):
    """
    TestCasePatchV2Dto
    """ # noqa: E501
    automated: Optional[StrictBool] = None
    custom_fields: Optional[List[CustomFieldValueWithCfDto]] = Field(default=None, alias="customFields")
    deleted: Optional[StrictBool] = None
    description: Optional[StrictStr] = None
    expected_result: Optional[StrictStr] = Field(default=None, alias="expectedResult")
    external: Optional[StrictBool] = None
    full_name: Optional[StrictStr] = Field(default=None, alias="fullName")
    links: Optional[List[ExternalLinkDto]] = None
    members: Optional[List[MemberDto]] = None
    name: Optional[StrictStr] = None
    precondition: Optional[StrictStr] = None
    scenario: Optional[TestCaseScenarioV2Dto] = None
    status_id: Optional[StrictInt] = Field(default=None, alias="statusId")
    tags: Optional[List[TestTagDto]] = None
    test_layer_id: Optional[StrictInt] = Field(default=None, alias="testLayerId")
    workflow_id: Optional[StrictInt] = Field(default=None, alias="workflowId")
    __properties: ClassVar[List[str]] = ["automated", "customFields", "deleted", "description", "expectedResult", "external", "fullName", "links", "members", "name", "precondition", "scenario", "statusId", "tags", "testLayerId", "workflowId"]

    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 TestCasePatchV2Dto 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 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 scenario
        if self.scenario:
            _dict['scenario'] = self.scenario.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
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of TestCasePatchV2Dto 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"),
            "customFields": [CustomFieldValueWithCfDto.from_dict(_item) for _item in obj["customFields"]] if obj.get("customFields") is not None else None,
            "deleted": obj.get("deleted"),
            "description": obj.get("description"),
            "expectedResult": obj.get("expectedResult"),
            "external": obj.get("external"),
            "fullName": obj.get("fullName"),
            "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"),
            "precondition": obj.get("precondition"),
            "scenario": TestCaseScenarioV2Dto.from_dict(obj["scenario"]) if obj.get("scenario") is not None else None,
            "statusId": obj.get("statusId"),
            "tags": [TestTagDto.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "testLayerId": obj.get("testLayerId"),
            "workflowId": obj.get("workflowId")
        })
        return _obj


