# 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 json
import pprint
from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator
from typing import Any, List, Optional
from src.client.generated.models.custom_field_import_field_mapping import CustomFieldImportFieldMapping
from src.client.generated.models.issue_import_field_mapping import IssueImportFieldMapping
from src.client.generated.models.link_import_field_mapping import LinkImportFieldMapping
from src.client.generated.models.multi_value_import_field_mapping import MultiValueImportFieldMapping
from src.client.generated.models.role_import_field_mapping import RoleImportFieldMapping
from src.client.generated.models.tag_import_field_mapping import TagImportFieldMapping
from src.client.generated.models.test_case_import_mapping import TestCaseImportMapping
from src.client.generated.models.test_key_import_field_mapping import TestKeyImportFieldMapping
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

TESTCASECSVIMPORTOPTIONSMAPPINGINNER_ONE_OF_SCHEMAS = ["CustomFieldImportFieldMapping", "IssueImportFieldMapping", "LinkImportFieldMapping", "MultiValueImportFieldMapping", "RoleImportFieldMapping", "TagImportFieldMapping", "TestCaseImportMapping", "TestKeyImportFieldMapping"]

class TestCaseCsvImportOptionsMappingInner(BaseModel):
    """
    TestCaseCsvImportOptionsMappingInner
    """
    # data type: TestCaseImportMapping
    oneof_schema_1_validator: Optional[TestCaseImportMapping] = None
    # data type: CustomFieldImportFieldMapping
    oneof_schema_2_validator: Optional[CustomFieldImportFieldMapping] = None
    # data type: IssueImportFieldMapping
    oneof_schema_3_validator: Optional[IssueImportFieldMapping] = None
    # data type: LinkImportFieldMapping
    oneof_schema_4_validator: Optional[LinkImportFieldMapping] = None
    # data type: MultiValueImportFieldMapping
    oneof_schema_5_validator: Optional[MultiValueImportFieldMapping] = None
    # data type: RoleImportFieldMapping
    oneof_schema_6_validator: Optional[RoleImportFieldMapping] = None
    # data type: TagImportFieldMapping
    oneof_schema_7_validator: Optional[TagImportFieldMapping] = None
    # data type: TestKeyImportFieldMapping
    oneof_schema_8_validator: Optional[TestKeyImportFieldMapping] = None
    actual_instance: Optional[Union[CustomFieldImportFieldMapping, IssueImportFieldMapping, LinkImportFieldMapping, MultiValueImportFieldMapping, RoleImportFieldMapping, TagImportFieldMapping, TestCaseImportMapping, TestKeyImportFieldMapping]] = None
    one_of_schemas: Set[str] = { "CustomFieldImportFieldMapping", "IssueImportFieldMapping", "LinkImportFieldMapping", "MultiValueImportFieldMapping", "RoleImportFieldMapping", "TagImportFieldMapping", "TestCaseImportMapping", "TestKeyImportFieldMapping" }

    model_config = ConfigDict(
        validate_assignment=True,
        protected_namespaces=(),
    )


    discriminator_value_class_map: Dict[str, str] = {
    }

    def __init__(self, *args, **kwargs) -> None:
        if args:
            if len(args) > 1:
                raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
            if kwargs:
                raise ValueError("If a position argument is used, keyword arguments cannot be used.")
            super().__init__(actual_instance=args[0])
        else:
            super().__init__(**kwargs)

    @field_validator('actual_instance')
    def actual_instance_must_validate_oneof(cls, v):
        instance = TestCaseCsvImportOptionsMappingInner.model_construct()
        error_messages = []
        match = 0
        # validate data type: TestCaseImportMapping
        if not isinstance(v, TestCaseImportMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `TestCaseImportMapping`")
        else:
            match += 1
        # validate data type: CustomFieldImportFieldMapping
        if not isinstance(v, CustomFieldImportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CustomFieldImportFieldMapping`")
        else:
            match += 1
        # validate data type: IssueImportFieldMapping
        if not isinstance(v, IssueImportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IssueImportFieldMapping`")
        else:
            match += 1
        # validate data type: LinkImportFieldMapping
        if not isinstance(v, LinkImportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LinkImportFieldMapping`")
        else:
            match += 1
        # validate data type: MultiValueImportFieldMapping
        if not isinstance(v, MultiValueImportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MultiValueImportFieldMapping`")
        else:
            match += 1
        # validate data type: RoleImportFieldMapping
        if not isinstance(v, RoleImportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `RoleImportFieldMapping`")
        else:
            match += 1
        # validate data type: TagImportFieldMapping
        if not isinstance(v, TagImportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `TagImportFieldMapping`")
        else:
            match += 1
        # validate data type: TestKeyImportFieldMapping
        if not isinstance(v, TestKeyImportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `TestKeyImportFieldMapping`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in TestCaseCsvImportOptionsMappingInner with oneOf schemas: CustomFieldImportFieldMapping, IssueImportFieldMapping, LinkImportFieldMapping, MultiValueImportFieldMapping, RoleImportFieldMapping, TagImportFieldMapping, TestCaseImportMapping, TestKeyImportFieldMapping. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in TestCaseCsvImportOptionsMappingInner with oneOf schemas: CustomFieldImportFieldMapping, IssueImportFieldMapping, LinkImportFieldMapping, MultiValueImportFieldMapping, RoleImportFieldMapping, TagImportFieldMapping, TestCaseImportMapping, TestKeyImportFieldMapping. Details: " + ", ".join(error_messages))
        else:
            return v

    @classmethod
    def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
        return cls.from_json(json.dumps(obj))

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Returns the object represented by the json string"""
        instance = cls.model_construct()
        error_messages = []
        match = 0

        # deserialize data into TestCaseImportMapping
        try:
            instance.actual_instance = TestCaseImportMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CustomFieldImportFieldMapping
        try:
            instance.actual_instance = CustomFieldImportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IssueImportFieldMapping
        try:
            instance.actual_instance = IssueImportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LinkImportFieldMapping
        try:
            instance.actual_instance = LinkImportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into MultiValueImportFieldMapping
        try:
            instance.actual_instance = MultiValueImportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into RoleImportFieldMapping
        try:
            instance.actual_instance = RoleImportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into TagImportFieldMapping
        try:
            instance.actual_instance = TagImportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into TestKeyImportFieldMapping
        try:
            instance.actual_instance = TestKeyImportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))

        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when deserializing the JSON string into TestCaseCsvImportOptionsMappingInner with oneOf schemas: CustomFieldImportFieldMapping, IssueImportFieldMapping, LinkImportFieldMapping, MultiValueImportFieldMapping, RoleImportFieldMapping, TagImportFieldMapping, TestCaseImportMapping, TestKeyImportFieldMapping. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into TestCaseCsvImportOptionsMappingInner with oneOf schemas: CustomFieldImportFieldMapping, IssueImportFieldMapping, LinkImportFieldMapping, MultiValueImportFieldMapping, RoleImportFieldMapping, TagImportFieldMapping, TestCaseImportMapping, TestKeyImportFieldMapping. Details: " + ", ".join(error_messages))
        else:
            return instance

    def to_json(self) -> str:
        """Returns the JSON representation of the actual instance"""
        if self.actual_instance is None:
            return "null"

        if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json):
            return self.actual_instance.to_json()
        else:
            return json.dumps(self.actual_instance)

    def to_dict(self) -> Optional[Union[Dict[str, Any], CustomFieldImportFieldMapping, IssueImportFieldMapping, LinkImportFieldMapping, MultiValueImportFieldMapping, RoleImportFieldMapping, TagImportFieldMapping, TestCaseImportMapping, TestKeyImportFieldMapping]]:
        """Returns the dict representation of the actual instance"""
        if self.actual_instance is None:
            return None

        if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
            return self.actual_instance.to_dict()
        else:
            # primitive type
            return self.actual_instance

    def to_str(self) -> str:
        """Returns the string representation of the actual instance"""
        return pprint.pformat(self.model_dump())


