# coding: utf-8

"""
    Zuora API Reference

    REST API reference for the Zuora Billing, Payments, and Central Platform! Check out the [REST API Overview](https://www.zuora.com/developer/api-references/api/overview/).

    The version of the OpenAPI document: 2024-05-20
    Contact: docs@zuora.com
    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 zuora_sdk.models.create_ach_payment_method import CreateACHPaymentMethod
from zuora_sdk.models.create_autogiro_payment_method import CreateAutogiroPaymentMethod
from zuora_sdk.models.create_bacs_payment_method import CreateBacsPaymentMethod
from zuora_sdk.models.create_becs_payment_method import CreateBecsPaymentMethod
from zuora_sdk.models.create_becsnz_payment_method import CreateBecsnzPaymentMethod
from zuora_sdk.models.create_betalingsservice_payment_method import CreateBetalingsservicePaymentMethod
from zuora_sdk.models.create_cc_reference_transaction_payment_method import CreateCCReferenceTransactionPaymentMethod
from zuora_sdk.models.create_credit_card_payment_method import CreateCreditCardPaymentMethod
from zuora_sdk.models.create_open_payment_method import CreateOpenPaymentMethod
from zuora_sdk.models.create_pad_payment_method import CreatePADPaymentMethod
from zuora_sdk.models.create_pay_pal_adaptive_payment_method import CreatePayPalAdaptivePaymentMethod
from zuora_sdk.models.create_pay_pal_cp_payment_method import CreatePayPalCPPaymentMethod
from zuora_sdk.models.create_pay_pal_ec_payment_method import CreatePayPalECPaymentMethod
from zuora_sdk.models.create_pay_pal_native_ec_payment_method import CreatePayPalNativeECPaymentMethod
from zuora_sdk.models.create_sepa_payment_method import CreateSEPAPaymentMethod
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

CREATEPAYMENTMETHODREQUEST_ONE_OF_SCHEMAS = ["CreateACHPaymentMethod", "CreateAutogiroPaymentMethod", "CreateBacsPaymentMethod", "CreateBecsPaymentMethod", "CreateBecsnzPaymentMethod", "CreateBetalingsservicePaymentMethod", "CreateCCReferenceTransactionPaymentMethod", "CreateCreditCardPaymentMethod", "CreateOpenPaymentMethod", "CreatePADPaymentMethod", "CreatePayPalAdaptivePaymentMethod", "CreatePayPalCPPaymentMethod", "CreatePayPalECPaymentMethod", "CreatePayPalNativeECPaymentMethod", "CreateSEPAPaymentMethod"]

class CreatePaymentMethodRequest(BaseModel):
    """
    CreatePaymentMethodRequest
    """
    # data type: CreatePayPalECPaymentMethod
    oneof_schema_1_validator: Optional[CreatePayPalECPaymentMethod] = None
    # data type: CreatePayPalCPPaymentMethod
    oneof_schema_2_validator: Optional[CreatePayPalCPPaymentMethod] = None
    # data type: CreatePayPalAdaptivePaymentMethod
    oneof_schema_3_validator: Optional[CreatePayPalAdaptivePaymentMethod] = None
    # data type: CreatePayPalNativeECPaymentMethod
    oneof_schema_4_validator: Optional[CreatePayPalNativeECPaymentMethod] = None
    # data type: CreateCreditCardPaymentMethod
    oneof_schema_5_validator: Optional[CreateCreditCardPaymentMethod] = None
    # data type: CreateCCReferenceTransactionPaymentMethod
    oneof_schema_6_validator: Optional[CreateCCReferenceTransactionPaymentMethod] = None
    # data type: CreateACHPaymentMethod
    oneof_schema_7_validator: Optional[CreateACHPaymentMethod] = None
    # data type: CreateBetalingsservicePaymentMethod
    oneof_schema_8_validator: Optional[CreateBetalingsservicePaymentMethod] = None
    # data type: CreateAutogiroPaymentMethod
    oneof_schema_9_validator: Optional[CreateAutogiroPaymentMethod] = None
    # data type: CreateBacsPaymentMethod
    oneof_schema_10_validator: Optional[CreateBacsPaymentMethod] = None
    # data type: CreateSEPAPaymentMethod
    oneof_schema_11_validator: Optional[CreateSEPAPaymentMethod] = None
    # data type: CreateBecsPaymentMethod
    oneof_schema_12_validator: Optional[CreateBecsPaymentMethod] = None
    # data type: CreateBecsnzPaymentMethod
    oneof_schema_13_validator: Optional[CreateBecsnzPaymentMethod] = None
    # data type: CreatePADPaymentMethod
    oneof_schema_14_validator: Optional[CreatePADPaymentMethod] = None
    # data type: CreateOpenPaymentMethod
    oneof_schema_15_validator: Optional[CreateOpenPaymentMethod] = None
    actual_instance: Optional[Union[CreateACHPaymentMethod, CreateAutogiroPaymentMethod, CreateBacsPaymentMethod, CreateBecsPaymentMethod, CreateBecsnzPaymentMethod, CreateBetalingsservicePaymentMethod, CreateCCReferenceTransactionPaymentMethod, CreateCreditCardPaymentMethod, CreateOpenPaymentMethod, CreatePADPaymentMethod, CreatePayPalAdaptivePaymentMethod, CreatePayPalCPPaymentMethod, CreatePayPalECPaymentMethod, CreatePayPalNativeECPaymentMethod, CreateSEPAPaymentMethod]] = None
    one_of_schemas: Set[str] = { "CreateACHPaymentMethod", "CreateAutogiroPaymentMethod", "CreateBacsPaymentMethod", "CreateBecsPaymentMethod", "CreateBecsnzPaymentMethod", "CreateBetalingsservicePaymentMethod", "CreateCCReferenceTransactionPaymentMethod", "CreateCreditCardPaymentMethod", "CreateOpenPaymentMethod", "CreatePADPaymentMethod", "CreatePayPalAdaptivePaymentMethod", "CreatePayPalCPPaymentMethod", "CreatePayPalECPaymentMethod", "CreatePayPalNativeECPaymentMethod", "CreateSEPAPaymentMethod" }

    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 = CreatePaymentMethodRequest.model_construct()
        error_messages = []
        match = 0
        # validate data type: CreatePayPalECPaymentMethod
        if not isinstance(v, CreatePayPalECPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreatePayPalECPaymentMethod`")
        else:
            match += 1
        # validate data type: CreatePayPalCPPaymentMethod
        if not isinstance(v, CreatePayPalCPPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreatePayPalCPPaymentMethod`")
        else:
            match += 1
        # validate data type: CreatePayPalAdaptivePaymentMethod
        if not isinstance(v, CreatePayPalAdaptivePaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreatePayPalAdaptivePaymentMethod`")
        else:
            match += 1
        # validate data type: CreatePayPalNativeECPaymentMethod
        if not isinstance(v, CreatePayPalNativeECPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreatePayPalNativeECPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateCreditCardPaymentMethod
        if not isinstance(v, CreateCreditCardPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateCreditCardPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateCCReferenceTransactionPaymentMethod
        if not isinstance(v, CreateCCReferenceTransactionPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateCCReferenceTransactionPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateACHPaymentMethod
        if not isinstance(v, CreateACHPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateACHPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateBetalingsservicePaymentMethod
        if not isinstance(v, CreateBetalingsservicePaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateBetalingsservicePaymentMethod`")
        else:
            match += 1
        # validate data type: CreateAutogiroPaymentMethod
        if not isinstance(v, CreateAutogiroPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateAutogiroPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateBacsPaymentMethod
        if not isinstance(v, CreateBacsPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateBacsPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateSEPAPaymentMethod
        if not isinstance(v, CreateSEPAPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateSEPAPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateBecsPaymentMethod
        if not isinstance(v, CreateBecsPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateBecsPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateBecsnzPaymentMethod
        if not isinstance(v, CreateBecsnzPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateBecsnzPaymentMethod`")
        else:
            match += 1
        # validate data type: CreatePADPaymentMethod
        if not isinstance(v, CreatePADPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreatePADPaymentMethod`")
        else:
            match += 1
        # validate data type: CreateOpenPaymentMethod
        if not isinstance(v, CreateOpenPaymentMethod):
            error_messages.append(f"Error! Input type `{type(v)}` is not `CreateOpenPaymentMethod`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in CreatePaymentMethodRequest with oneOf schemas: CreateACHPaymentMethod, CreateAutogiroPaymentMethod, CreateBacsPaymentMethod, CreateBecsPaymentMethod, CreateBecsnzPaymentMethod, CreateBetalingsservicePaymentMethod, CreateCCReferenceTransactionPaymentMethod, CreateCreditCardPaymentMethod, CreateOpenPaymentMethod, CreatePADPaymentMethod, CreatePayPalAdaptivePaymentMethod, CreatePayPalCPPaymentMethod, CreatePayPalECPaymentMethod, CreatePayPalNativeECPaymentMethod, CreateSEPAPaymentMethod. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in CreatePaymentMethodRequest with oneOf schemas: CreateACHPaymentMethod, CreateAutogiroPaymentMethod, CreateBacsPaymentMethod, CreateBecsPaymentMethod, CreateBecsnzPaymentMethod, CreateBetalingsservicePaymentMethod, CreateCCReferenceTransactionPaymentMethod, CreateCreditCardPaymentMethod, CreateOpenPaymentMethod, CreatePADPaymentMethod, CreatePayPalAdaptivePaymentMethod, CreatePayPalCPPaymentMethod, CreatePayPalECPaymentMethod, CreatePayPalNativeECPaymentMethod, CreateSEPAPaymentMethod. 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 CreatePayPalECPaymentMethod
        try:
            instance.actual_instance = CreatePayPalECPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreatePayPalCPPaymentMethod
        try:
            instance.actual_instance = CreatePayPalCPPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreatePayPalAdaptivePaymentMethod
        try:
            instance.actual_instance = CreatePayPalAdaptivePaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreatePayPalNativeECPaymentMethod
        try:
            instance.actual_instance = CreatePayPalNativeECPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateCreditCardPaymentMethod
        try:
            instance.actual_instance = CreateCreditCardPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateCCReferenceTransactionPaymentMethod
        try:
            instance.actual_instance = CreateCCReferenceTransactionPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateACHPaymentMethod
        try:
            instance.actual_instance = CreateACHPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateBetalingsservicePaymentMethod
        try:
            instance.actual_instance = CreateBetalingsservicePaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateAutogiroPaymentMethod
        try:
            instance.actual_instance = CreateAutogiroPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateBacsPaymentMethod
        try:
            instance.actual_instance = CreateBacsPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateSEPAPaymentMethod
        try:
            instance.actual_instance = CreateSEPAPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateBecsPaymentMethod
        try:
            instance.actual_instance = CreateBecsPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateBecsnzPaymentMethod
        try:
            instance.actual_instance = CreateBecsnzPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreatePADPaymentMethod
        try:
            instance.actual_instance = CreatePADPaymentMethod.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into CreateOpenPaymentMethod
        try:
            instance.actual_instance = CreateOpenPaymentMethod.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 CreatePaymentMethodRequest with oneOf schemas: CreateACHPaymentMethod, CreateAutogiroPaymentMethod, CreateBacsPaymentMethod, CreateBecsPaymentMethod, CreateBecsnzPaymentMethod, CreateBetalingsservicePaymentMethod, CreateCCReferenceTransactionPaymentMethod, CreateCreditCardPaymentMethod, CreateOpenPaymentMethod, CreatePADPaymentMethod, CreatePayPalAdaptivePaymentMethod, CreatePayPalCPPaymentMethod, CreatePayPalECPaymentMethod, CreatePayPalNativeECPaymentMethod, CreateSEPAPaymentMethod. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into CreatePaymentMethodRequest with oneOf schemas: CreateACHPaymentMethod, CreateAutogiroPaymentMethod, CreateBacsPaymentMethod, CreateBecsPaymentMethod, CreateBecsnzPaymentMethod, CreateBetalingsservicePaymentMethod, CreateCCReferenceTransactionPaymentMethod, CreateCreditCardPaymentMethod, CreateOpenPaymentMethod, CreatePADPaymentMethod, CreatePayPalAdaptivePaymentMethod, CreatePayPalCPPaymentMethod, CreatePayPalECPaymentMethod, CreatePayPalNativeECPaymentMethod, CreateSEPAPaymentMethod. 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], CreateACHPaymentMethod, CreateAutogiroPaymentMethod, CreateBacsPaymentMethod, CreateBecsPaymentMethod, CreateBecsnzPaymentMethod, CreateBetalingsservicePaymentMethod, CreateCCReferenceTransactionPaymentMethod, CreateCreditCardPaymentMethod, CreateOpenPaymentMethod, CreatePADPaymentMethod, CreatePayPalAdaptivePaymentMethod, CreatePayPalCPPaymentMethod, CreatePayPalECPaymentMethod, CreatePayPalNativeECPaymentMethod, CreateSEPAPaymentMethod]]:
        """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())


