# 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_export_field_mapping import CustomFieldExportFieldMapping
from src.client.generated.models.example_export_field_mapping import ExampleExportFieldMapping
from src.client.generated.models.export_field_mapping_test_case_export_field import ExportFieldMappingTestCaseExportField
from src.client.generated.models.issue_integration_export_field_mapping import IssueIntegrationExportFieldMapping
from src.client.generated.models.link_export_field_mapping import LinkExportFieldMapping
from src.client.generated.models.multi_value_export_field_mapping import MultiValueExportFieldMapping
from src.client.generated.models.role_export_field_mapping import RoleExportFieldMapping
from src.client.generated.models.scenario_export_field_mapping import ScenarioExportFieldMapping
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

TESTCASEBULKEXPORTCSVOPTIONSMAPPINGINNER_ONE_OF_SCHEMAS = ["CustomFieldExportFieldMapping", "ExampleExportFieldMapping", "ExportFieldMappingTestCaseExportField", "IssueIntegrationExportFieldMapping", "LinkExportFieldMapping", "MultiValueExportFieldMapping", "RoleExportFieldMapping", "ScenarioExportFieldMapping"]

class TestCaseBulkExportCsvOptionsMappingInner(BaseModel):
    """
    TestCaseBulkExportCsvOptionsMappingInner
    """
    # data type: ExportFieldMappingTestCaseExportField
    oneof_schema_1_validator: Optional[ExportFieldMappingTestCaseExportField] = None
    # data type: CustomFieldExportFieldMapping
    oneof_schema_2_validator: Optional[CustomFieldExportFieldMapping] = None
    # data type: ExampleExportFieldMapping
    oneof_schema_3_validator: Optional[ExampleExportFieldMapping] = None
    # data type: IssueIntegrationExportFieldMapping
    oneof_schema_4_validator: Optional[IssueIntegrationExportFieldMapping] = None
    # data type: LinkExportFieldMapping
    oneof_schema_5_validator: Optional[LinkExportFieldMapping] = None
    # data type: MultiValueExportFieldMapping
    oneof_schema_6_validator: Optional[MultiValueExportFieldMapping] = None
    # data type: RoleExportFieldMapping
    oneof_schema_7_validator: Optional[RoleExportFieldMapping] = None
    # data type: ScenarioExportFieldMapping
    oneof_schema_8_validator: Optional[ScenarioExportFieldMapping] = None
    actual_instance: Optional[Union[CustomFieldExportFieldMapping, ExampleExportFieldMapping, ExportFieldMappingTestCaseExportField, IssueIntegrationExportFieldMapping, LinkExportFieldMapping, MultiValueExportFieldMapping, RoleExportFieldMapping, ScenarioExportFieldMapping]] = None
    one_of_schemas: Set[str] = { "CustomFieldExportFieldMapping", "ExampleExportFieldMapping", "ExportFieldMappingTestCaseExportField", "IssueIntegrationExportFieldMapping", "LinkExportFieldMapping", "MultiValueExportFieldMapping", "RoleExportFieldMapping", "ScenarioExportFieldMapping" }

    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 = TestCaseBulkExportCsvOptionsMappingInner.model_construct()
        error_messages = []
        match = 0
        # validate data type: ExportFieldMappingTestCaseExportField
        if not isinstance(v, ExportFieldMappingTestCaseExportField):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ExportFieldMappingTestCaseExportField`")
        else:
            match += 1
        # validate data type: CustomFieldExportFieldMapping
        if not isinstance(v, CustomFieldExportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CustomFieldExportFieldMapping`")
        else:
            match += 1
        # validate data type: ExampleExportFieldMapping
        if not isinstance(v, ExampleExportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ExampleExportFieldMapping`")
        else:
            match += 1
        # validate data type: IssueIntegrationExportFieldMapping
        if not isinstance(v, IssueIntegrationExportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `IssueIntegrationExportFieldMapping`")
        else:
            match += 1
        # validate data type: LinkExportFieldMapping
        if not isinstance(v, LinkExportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LinkExportFieldMapping`")
        else:
            match += 1
        # validate data type: MultiValueExportFieldMapping
        if not isinstance(v, MultiValueExportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MultiValueExportFieldMapping`")
        else:
            match += 1
        # validate data type: RoleExportFieldMapping
        if not isinstance(v, RoleExportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `RoleExportFieldMapping`")
        else:
            match += 1
        # validate data type: ScenarioExportFieldMapping
        if not isinstance(v, ScenarioExportFieldMapping):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ScenarioExportFieldMapping`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in TestCaseBulkExportCsvOptionsMappingInner with oneOf schemas: CustomFieldExportFieldMapping, ExampleExportFieldMapping, ExportFieldMappingTestCaseExportField, IssueIntegrationExportFieldMapping, LinkExportFieldMapping, MultiValueExportFieldMapping, RoleExportFieldMapping, ScenarioExportFieldMapping. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in TestCaseBulkExportCsvOptionsMappingInner with oneOf schemas: CustomFieldExportFieldMapping, ExampleExportFieldMapping, ExportFieldMappingTestCaseExportField, IssueIntegrationExportFieldMapping, LinkExportFieldMapping, MultiValueExportFieldMapping, RoleExportFieldMapping, ScenarioExportFieldMapping. 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 ExportFieldMappingTestCaseExportField
        try:
            instance.actual_instance = ExportFieldMappingTestCaseExportField.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CustomFieldExportFieldMapping
        try:
            instance.actual_instance = CustomFieldExportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ExampleExportFieldMapping
        try:
            instance.actual_instance = ExampleExportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into IssueIntegrationExportFieldMapping
        try:
            instance.actual_instance = IssueIntegrationExportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LinkExportFieldMapping
        try:
            instance.actual_instance = LinkExportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into MultiValueExportFieldMapping
        try:
            instance.actual_instance = MultiValueExportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into RoleExportFieldMapping
        try:
            instance.actual_instance = RoleExportFieldMapping.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ScenarioExportFieldMapping
        try:
            instance.actual_instance = ScenarioExportFieldMapping.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 TestCaseBulkExportCsvOptionsMappingInner with oneOf schemas: CustomFieldExportFieldMapping, ExampleExportFieldMapping, ExportFieldMappingTestCaseExportField, IssueIntegrationExportFieldMapping, LinkExportFieldMapping, MultiValueExportFieldMapping, RoleExportFieldMapping, ScenarioExportFieldMapping. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into TestCaseBulkExportCsvOptionsMappingInner with oneOf schemas: CustomFieldExportFieldMapping, ExampleExportFieldMapping, ExportFieldMappingTestCaseExportField, IssueIntegrationExportFieldMapping, LinkExportFieldMapping, MultiValueExportFieldMapping, RoleExportFieldMapping, ScenarioExportFieldMapping. 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], CustomFieldExportFieldMapping, ExampleExportFieldMapping, ExportFieldMappingTestCaseExportField, IssueIntegrationExportFieldMapping, LinkExportFieldMapping, MultiValueExportFieldMapping, RoleExportFieldMapping, ScenarioExportFieldMapping]]:
        """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())


