# coding: utf-8

"""
    CampaignManagementService

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    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 openapi_client.models.campaign.ad_api_error import AdApiError
from openapi_client.models.campaign.ad_api_fault_detail import AdApiFaultDetail
from openapi_client.models.campaign.ad_center_authentication_fault import AdCenterAuthenticationFault
from openapi_client.models.campaign.ad_center_authorization_fault import AdCenterAuthorizationFault
from openapi_client.models.campaign.ad_center_fault import AdCenterFault
from openapi_client.models.campaign.ad_center_internal_error_fault import AdCenterInternalErrorFault
from openapi_client.models.campaign.ad_center_system_fault import AdCenterSystemFault
from openapi_client.models.campaign.api_fault_detail import ApiFaultDetail
from openapi_client.models.campaign.authentication_fault_code import AuthenticationFaultCode
from openapi_client.models.campaign.batch_error import BatchError
from openapi_client.models.campaign.editorial_api_fault_detail import EditorialApiFaultDetail
from openapi_client.models.campaign.editorial_error import EditorialError
from openapi_client.models.campaign.fault_source import FaultSource
from openapi_client.models.campaign.operation_error import OperationError
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

ApplicationFault_ONE_OF_SCHEMAS = ["AdApiFaultDetail", "AdCenterAuthenticationFault", "AdCenterAuthorizationFault", "AdCenterFault", "AdCenterInternalErrorFault", "AdCenterSystemFault", "ApiFaultDetail", "EditorialApiFaultDetail"]

class ApplicationFault(BaseModel):
    """
    ApplicationFault
    """
    # data type: AdApiFaultDetail
    oneof_schema_ad_api_fault_detail_validator: Optional[AdApiFaultDetail] = None
    # data type: AdCenterAuthenticationFault
    oneof_schema_ad_center_authentication_fault_validator: Optional[AdCenterAuthenticationFault] = None
    # data type: AdCenterAuthorizationFault
    oneof_schema_ad_center_authorization_fault_validator: Optional[AdCenterAuthorizationFault] = None
    # data type: AdCenterFault
    oneof_schema_ad_center_fault_validator: Optional[AdCenterFault] = None
    # data type: AdCenterInternalErrorFault
    oneof_schema_ad_center_internal_error_fault_validator: Optional[AdCenterInternalErrorFault] = None
    # data type: AdCenterSystemFault
    oneof_schema_ad_center_system_fault_validator: Optional[AdCenterSystemFault] = None
    # data type: ApiFaultDetail
    oneof_schema_api_fault_detail_validator: Optional[ApiFaultDetail] = None
    # data type: EditorialApiFaultDetail
    oneof_schema_editorial_api_fault_detail_validator: Optional[EditorialApiFaultDetail] = None
    actual_instance: Optional[Union[AdApiFaultDetail, AdCenterAuthenticationFault, AdCenterAuthorizationFault, AdCenterFault, AdCenterInternalErrorFault, AdCenterSystemFault, ApiFaultDetail, EditorialApiFaultDetail]] = None
    one_of_schemas: Set[str] = { "AdApiFaultDetail", "AdCenterAuthenticationFault", "AdCenterAuthorizationFault", "AdCenterFault", "AdCenterInternalErrorFault", "AdCenterSystemFault", "ApiFaultDetail", "EditorialApiFaultDetail" }

    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):
        if v is None:
            return v

        instance = ApplicationFault.model_construct()
        error_messages = []
        match = 0
        # validate data type: AdApiFaultDetail
        if not isinstance(v, AdApiFaultDetail):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AdApiFaultDetail`")
        else:
            match += 1
        # validate data type: AdCenterAuthenticationFault
        if not isinstance(v, AdCenterAuthenticationFault):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AdCenterAuthenticationFault`")
        else:
            match += 1
        # validate data type: AdCenterAuthorizationFault
        if not isinstance(v, AdCenterAuthorizationFault):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AdCenterAuthorizationFault`")
        else:
            match += 1
        # validate data type: AdCenterFault
        if not isinstance(v, AdCenterFault):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AdCenterFault`")
        else:
            match += 1
        # validate data type: AdCenterInternalErrorFault
        if not isinstance(v, AdCenterInternalErrorFault):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AdCenterInternalErrorFault`")
        else:
            match += 1
        # validate data type: AdCenterSystemFault
        if not isinstance(v, AdCenterSystemFault):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AdCenterSystemFault`")
        else:
            match += 1
        # validate data type: ApiFaultDetail
        if not isinstance(v, ApiFaultDetail):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ApiFaultDetail`")
        else:
            match += 1
        # validate data type: EditorialApiFaultDetail
        if not isinstance(v, EditorialApiFaultDetail):
            error_messages.append(f"Error! Input type `{type(v)}` is not `EditorialApiFaultDetail`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in ApplicationFault with oneOf schemas: AdApiFaultDetail, AdCenterAuthenticationFault, AdCenterAuthorizationFault, AdCenterFault, AdCenterInternalErrorFault, AdCenterSystemFault, ApiFaultDetail, EditorialApiFaultDetail. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in ApplicationFault with oneOf schemas: AdApiFaultDetail, AdCenterAuthenticationFault, AdCenterAuthorizationFault, AdCenterFault, AdCenterInternalErrorFault, AdCenterSystemFault, ApiFaultDetail, EditorialApiFaultDetail. 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: Optional[str]) -> Self:
        """Returns the object represented by the json string"""
        instance = cls.model_construct()
        if json_str is None:
            return instance

        error_messages = []
        match = 0

        # use oneOf discriminator to lookup the data type
        _data_type = json.loads(json_str).get("Type")
        if not _data_type:
            raise ValueError("Failed to lookup data type from the field `Type` in the input.")

		# check if data type is `AdApiFaultDetail`
        if _data_type == "AdApiFaultDetail":
            instance.actual_instance = AdApiFaultDetail.from_json(json_str)
            return instance
			
		# check if data type is `AdCenterAuthenticationFault`
        if _data_type == "AdCenterAuthenticationFault":
            instance.actual_instance = AdCenterAuthenticationFault.from_json(json_str)
            return instance
			
		# check if data type is `AdCenterAuthorizationFault`
        if _data_type == "AdCenterAuthorizationFault":
            instance.actual_instance = AdCenterAuthorizationFault.from_json(json_str)
            return instance
			
		# check if data type is `AdCenterFault`
        if _data_type == "AdCenterFault":
            instance.actual_instance = AdCenterFault.from_json(json_str)
            return instance
			
		# check if data type is `AdCenterInternalErrorFault`
        if _data_type == "AdCenterInternalErrorFault":
            instance.actual_instance = AdCenterInternalErrorFault.from_json(json_str)
            return instance
			
		# check if data type is `AdCenterSystemFault`
        if _data_type == "AdCenterSystemFault":
            instance.actual_instance = AdCenterSystemFault.from_json(json_str)
            return instance
			
		# check if data type is `ApiFaultDetail`
        if _data_type == "ApiFaultDetail":
            instance.actual_instance = ApiFaultDetail.from_json(json_str)
            return instance
			
		# check if data type is `EditorialApiFaultDetail`
        if _data_type == "EditorialApiFaultDetail":
            instance.actual_instance = EditorialApiFaultDetail.from_json(json_str)
            return instance
			

        # deserialize data into AdApiFaultDetail
        try:
            instance.actual_instance = AdApiFaultDetail.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AdCenterAuthenticationFault
        try:
            instance.actual_instance = AdCenterAuthenticationFault.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AdCenterAuthorizationFault
        try:
            instance.actual_instance = AdCenterAuthorizationFault.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AdCenterFault
        try:
            instance.actual_instance = AdCenterFault.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AdCenterInternalErrorFault
        try:
            instance.actual_instance = AdCenterInternalErrorFault.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AdCenterSystemFault
        try:
            instance.actual_instance = AdCenterSystemFault.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ApiFaultDetail
        try:
            instance.actual_instance = ApiFaultDetail.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into EditorialApiFaultDetail
        try:
            instance.actual_instance = EditorialApiFaultDetail.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 ApplicationFault with oneOf schemas: AdApiFaultDetail, AdCenterAuthenticationFault, AdCenterAuthorizationFault, AdCenterFault, AdCenterInternalErrorFault, AdCenterSystemFault, ApiFaultDetail, EditorialApiFaultDetail. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into ApplicationFault with oneOf schemas: AdApiFaultDetail, AdCenterAuthenticationFault, AdCenterAuthorizationFault, AdCenterFault, AdCenterInternalErrorFault, AdCenterSystemFault, ApiFaultDetail, EditorialApiFaultDetail. 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], AdApiFaultDetail, AdCenterAuthenticationFault, AdCenterAuthorizationFault, AdCenterFault, AdCenterInternalErrorFault, AdCenterSystemFault, ApiFaultDetail, EditorialApiFaultDetail]]:
        """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())

    def __getattr__(self, name):
        """Forward attribute access to actual_instance"""
        if self.actual_instance is not None and hasattr(self.actual_instance, name):
            return getattr(self.actual_instance, name)
        raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")

    def __setattr__(self, name, value):
        """Forward attribute setting to actual_instance"""
        if name in ['actual_instance', 'oneof_schema_ad_api_fault_detail_validator', 'oneof_schema_ad_center_authentication_fault_validator', 'oneof_schema_ad_center_authorization_fault_validator', 'oneof_schema_ad_center_fault_validator', 'oneof_schema_ad_center_internal_error_fault_validator', 'oneof_schema_ad_center_system_fault_validator', 'oneof_schema_api_fault_detail_validator', 'oneof_schema_editorial_api_fault_detail_validator', 'one_of_schemas', 'model_config', 'discriminator_value_class_map']:
            super().__setattr__(name, value)
        elif self.actual_instance is not None and hasattr(self.actual_instance, name):
            setattr(self.actual_instance, name, value)
        else:
            super().__setattr__(name, value)
