# coding: utf-8

"""
    Synctera API

    <h2>Let's build something great.</h2><p>Welcome to the official reference documentation for Synctera APIs. Our APIs are the best way to automate your company's banking needs and are designed to be easy to understand and implement.</p><p>We're continuously growing this library and what you see here is just the start, but if you need something specific or have a question, <a class='text-blue-600' href='https://synctera.com/contact' target='_blank' rel='noreferrer'>contact us</a>.</p>  # noqa: E501

    The version of the OpenAPI document: 0.41.0
    Contact: dev@swadesh.co
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


from __future__ import annotations
from inspect import getfullargspec
import json
import pprint
import re  # noqa: F401

from typing import Optional
from pydantic import BaseModel, Field, StrictStr, ValidationError, validator
from synctera_client_ng.models.account_depository import AccountDepository
from synctera_client_ng.models.patch_account_charge_secured import PatchAccountChargeSecured
from synctera_client_ng.models.patch_account_line_of_credit import PatchAccountLineOfCredit
from typing import Any, List
from pydantic import StrictStr, Field

PATCHACCOUNT_ANY_OF_SCHEMAS = ["AccountDepository", "PatchAccountChargeSecured", "PatchAccountLineOfCredit"]

class PatchAccount(BaseModel):
    """
    PatchAccount
    """

    # data type: AccountDepository
    anyof_schema_1_validator: Optional[AccountDepository] = None
    # data type: PatchAccountLineOfCredit
    anyof_schema_2_validator: Optional[PatchAccountLineOfCredit] = None
    # data type: PatchAccountChargeSecured
    anyof_schema_3_validator: Optional[PatchAccountChargeSecured] = None
    actual_instance: Any
    any_of_schemas: List[str] = Field(PATCHACCOUNT_ANY_OF_SCHEMAS, const=True)

    class Config:
        validate_assignment = True

    @validator('actual_instance')
    def actual_instance_must_validate_anyof(cls, v):
        instance = cls()
        error_messages = []
        # validate data type: AccountDepository
        if type(v) is not AccountDepository:
            error_messages.append(f"Error! Input type `{type(v)}` is not `AccountDepository`")
        else:
            return v

        # validate data type: PatchAccountLineOfCredit
        if type(v) is not PatchAccountLineOfCredit:
            error_messages.append(f"Error! Input type `{type(v)}` is not `PatchAccountLineOfCredit`")
        else:
            return v

        # validate data type: PatchAccountChargeSecured
        if type(v) is not PatchAccountChargeSecured:
            error_messages.append(f"Error! Input type `{type(v)}` is not `PatchAccountChargeSecured`")
        else:
            return v

        if error_messages:
            # no match
            raise ValueError("No match found when deserializing the JSON string into PatchAccount with anyOf schemas: AccountDepository, PatchAccountChargeSecured, PatchAccountLineOfCredit. Details: " + ", ".join(error_messages))
        else:
            return v

    @classmethod
    def from_dict(cls, obj: dict) -> PatchAccount:
        return cls.from_json(json.dumps(obj))

    @classmethod
    def from_json(cls, json_str: str) -> PatchAccount:
        """Returns the object represented by the json string"""
        instance = cls()
        error_messages = []
        # anyof_schema_1_validator: Optional[AccountDepository] = None
        try:
            instance.actual_instance = AccountDepository.from_json(json_str)
            return instance
        except ValidationError as e:
             error_messages.append(str(e))
        # anyof_schema_2_validator: Optional[PatchAccountLineOfCredit] = None
        try:
            instance.actual_instance = PatchAccountLineOfCredit.from_json(json_str)
            return instance
        except ValidationError as e:
             error_messages.append(str(e))
        # anyof_schema_3_validator: Optional[PatchAccountChargeSecured] = None
        try:
            instance.actual_instance = PatchAccountChargeSecured.from_json(json_str)
            return instance
        except ValidationError as e:
             error_messages.append(str(e))

        if error_messages:
            # no match
            raise ValueError("No match found when deserializing the JSON string into PatchAccount with anyOf schemas: AccountDepository, PatchAccountChargeSecured, PatchAccountLineOfCredit. 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 not None:
            return self.actual_instance.to_json()
        else:
            return "null"

    def to_dict(self) -> dict:
        """Returns the dict representation of the actual instance"""
        if self.actual_instance is not None:
            return self.actual_instance.to_dict()
        else:
            return dict()

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

