# coding: utf-8

"""
    Kiln API Docs (dev)

    This API provides reporting staking data on various protocols as well as network wide data, staking transaction crafting features and so on. In order to use it, you should first get an API token from your Kiln dashboard (applications section). If you don't have access to our dashboard, please get in touch at hello@kiln.fi. Once you have your API token, you can set it as a bearer token in your request headers.  ### Backward Compatibility  This is an experimental specification used for development and testing, do not rely on what is here unless you know the implications.  The official Kiln API specification following backward compatible changes can be found [here](/).  # noqa: E501

    The version of the OpenAPI document: 1.0.0
    Contact: contact@kiln.fi
    Generated by: https://openapi-generator.tech
"""


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

from typing import Any, List, Optional
from pydantic import BaseModel, Field, StrictStr, ValidationError, validator
from kiln_connect.openapi_client.models.sol_operation_create_account import SOLOperationCreateAccount
from kiln_connect.openapi_client.models.sol_operation_create_account_with_seed import SOLOperationCreateAccountWithSeed
from kiln_connect.openapi_client.models.sol_operation_deactivate import SOLOperationDeactivate
from kiln_connect.openapi_client.models.sol_operation_delegate import SOLOperationDelegate
from kiln_connect.openapi_client.models.sol_operation_merge import SOLOperationMerge
from kiln_connect.openapi_client.models.sol_operation_redelegate import SOLOperationRedelegate
from kiln_connect.openapi_client.models.sol_operation_split import SOLOperationSplit
from kiln_connect.openapi_client.models.sol_operation_withdraw import SOLOperationWithdraw
from typing import Any, List
from pydantic import StrictStr, Field

GETSOLOPERATIONS200RESPONSEDATAINNER_ONE_OF_SCHEMAS = ["SOLOperationCreateAccount", "SOLOperationCreateAccountWithSeed", "SOLOperationDeactivate", "SOLOperationDelegate", "SOLOperationMerge", "SOLOperationRedelegate", "SOLOperationSplit", "SOLOperationWithdraw"]

class GetSolOperations200ResponseDataInner(BaseModel):
    """
    GetSolOperations200ResponseDataInner
    """
    # data type: SOLOperationCreateAccountWithSeed
    oneof_schema_1_validator: Optional[SOLOperationCreateAccountWithSeed] = None
    # data type: SOLOperationCreateAccount
    oneof_schema_2_validator: Optional[SOLOperationCreateAccount] = None
    # data type: SOLOperationDelegate
    oneof_schema_3_validator: Optional[SOLOperationDelegate] = None
    # data type: SOLOperationDeactivate
    oneof_schema_4_validator: Optional[SOLOperationDeactivate] = None
    # data type: SOLOperationRedelegate
    oneof_schema_5_validator: Optional[SOLOperationRedelegate] = None
    # data type: SOLOperationSplit
    oneof_schema_6_validator: Optional[SOLOperationSplit] = None
    # data type: SOLOperationWithdraw
    oneof_schema_7_validator: Optional[SOLOperationWithdraw] = None
    # data type: SOLOperationMerge
    oneof_schema_8_validator: Optional[SOLOperationMerge] = None
    actual_instance: Any
    one_of_schemas: List[str] = Field(GETSOLOPERATIONS200RESPONSEDATAINNER_ONE_OF_SCHEMAS, const=True)

    class Config:
        validate_assignment = True

    discriminator_value_class_map = {
    }

    @validator('actual_instance')
    def actual_instance_must_validate_oneof(cls, v):
        instance = cls()
        error_messages = []
        match = 0
        # validate data type: SOLOperationCreateAccountWithSeed
        if type(v) is not SOLOperationCreateAccountWithSeed:
            error_messages.append(f"Error! Input type `{type(v)}` is not `SOLOperationCreateAccountWithSeed`")
        else:
            match += 1

        # validate data type: SOLOperationCreateAccount
        if type(v) is not SOLOperationCreateAccount:
            error_messages.append(f"Error! Input type `{type(v)}` is not `SOLOperationCreateAccount`")
        else:
            match += 1

        # validate data type: SOLOperationDelegate
        if type(v) is not SOLOperationDelegate:
            error_messages.append(f"Error! Input type `{type(v)}` is not `SOLOperationDelegate`")
        else:
            match += 1

        # validate data type: SOLOperationDeactivate
        if type(v) is not SOLOperationDeactivate:
            error_messages.append(f"Error! Input type `{type(v)}` is not `SOLOperationDeactivate`")
        else:
            match += 1

        # validate data type: SOLOperationRedelegate
        if type(v) is not SOLOperationRedelegate:
            error_messages.append(f"Error! Input type `{type(v)}` is not `SOLOperationRedelegate`")
        else:
            match += 1

        # validate data type: SOLOperationSplit
        if type(v) is not SOLOperationSplit:
            error_messages.append(f"Error! Input type `{type(v)}` is not `SOLOperationSplit`")
        else:
            match += 1

        # validate data type: SOLOperationWithdraw
        if type(v) is not SOLOperationWithdraw:
            error_messages.append(f"Error! Input type `{type(v)}` is not `SOLOperationWithdraw`")
        else:
            match += 1

        # validate data type: SOLOperationMerge
        if type(v) is not SOLOperationMerge:
            error_messages.append(f"Error! Input type `{type(v)}` is not `SOLOperationMerge`")
        else:
            match += 1

        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when deserializing the JSON string into GetSolOperations200ResponseDataInner with oneOf schemas: SOLOperationCreateAccount, SOLOperationCreateAccountWithSeed, SOLOperationDeactivate, SOLOperationDelegate, SOLOperationMerge, SOLOperationRedelegate, SOLOperationSplit, SOLOperationWithdraw. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into GetSolOperations200ResponseDataInner with oneOf schemas: SOLOperationCreateAccount, SOLOperationCreateAccountWithSeed, SOLOperationDeactivate, SOLOperationDelegate, SOLOperationMerge, SOLOperationRedelegate, SOLOperationSplit, SOLOperationWithdraw. Details: " + ", ".join(error_messages))
        else:
            return v

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

    @classmethod
    def from_json(cls, json_str: str) -> GetSolOperations200ResponseDataInner:
        """Returns the object represented by the json string"""
        instance = cls()
        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 `SOLOperationCreateAccount`
        if _data_type == "SOLOperationCreateAccount":
            instance.actual_instance = SOLOperationCreateAccount.from_json(json_str)
            return instance

        # check if data type is `SOLOperationCreateAccountWithSeed`
        if _data_type == "SOLOperationCreateAccountWithSeed":
            instance.actual_instance = SOLOperationCreateAccountWithSeed.from_json(json_str)
            return instance

        # check if data type is `SOLOperationDeactivate`
        if _data_type == "SOLOperationDeactivate":
            instance.actual_instance = SOLOperationDeactivate.from_json(json_str)
            return instance

        # check if data type is `SOLOperationDelegate`
        if _data_type == "SOLOperationDelegate":
            instance.actual_instance = SOLOperationDelegate.from_json(json_str)
            return instance

        # check if data type is `SOLOperationMerge`
        if _data_type == "SOLOperationMerge":
            instance.actual_instance = SOLOperationMerge.from_json(json_str)
            return instance

        # check if data type is `SOLOperationRedelegate`
        if _data_type == "SOLOperationRedelegate":
            instance.actual_instance = SOLOperationRedelegate.from_json(json_str)
            return instance

        # check if data type is `SOLOperationSplit`
        if _data_type == "SOLOperationSplit":
            instance.actual_instance = SOLOperationSplit.from_json(json_str)
            return instance

        # check if data type is `SOLOperationWithdraw`
        if _data_type == "SOLOperationWithdraw":
            instance.actual_instance = SOLOperationWithdraw.from_json(json_str)
            return instance

        # check if data type is `SOLOperationCreateAccount`
        if _data_type == "create_account":
            instance.actual_instance = SOLOperationCreateAccount.from_json(json_str)
            return instance

        # check if data type is `SOLOperationCreateAccountWithSeed`
        if _data_type == "create_account_with_seed":
            instance.actual_instance = SOLOperationCreateAccountWithSeed.from_json(json_str)
            return instance

        # check if data type is `SOLOperationDeactivate`
        if _data_type == "deactivate":
            instance.actual_instance = SOLOperationDeactivate.from_json(json_str)
            return instance

        # check if data type is `SOLOperationDelegate`
        if _data_type == "delegate":
            instance.actual_instance = SOLOperationDelegate.from_json(json_str)
            return instance

        # check if data type is `SOLOperationMerge`
        if _data_type == "merge":
            instance.actual_instance = SOLOperationMerge.from_json(json_str)
            return instance

        # check if data type is `SOLOperationRedelegate`
        if _data_type == "redelegate":
            instance.actual_instance = SOLOperationRedelegate.from_json(json_str)
            return instance

        # check if data type is `SOLOperationSplit`
        if _data_type == "split":
            instance.actual_instance = SOLOperationSplit.from_json(json_str)
            return instance

        # check if data type is `SOLOperationWithdraw`
        if _data_type == "withdraw":
            instance.actual_instance = SOLOperationWithdraw.from_json(json_str)
            return instance

        # deserialize data into SOLOperationCreateAccountWithSeed
        try:
            instance.actual_instance = SOLOperationCreateAccountWithSeed.from_json(json_str)
            match += 1
        except ValidationError as e:
            error_messages.append(str(e))
        # deserialize data into SOLOperationCreateAccount
        try:
            instance.actual_instance = SOLOperationCreateAccount.from_json(json_str)
            match += 1
        except ValidationError as e:
            error_messages.append(str(e))
        # deserialize data into SOLOperationDelegate
        try:
            instance.actual_instance = SOLOperationDelegate.from_json(json_str)
            match += 1
        except ValidationError as e:
            error_messages.append(str(e))
        # deserialize data into SOLOperationDeactivate
        try:
            instance.actual_instance = SOLOperationDeactivate.from_json(json_str)
            match += 1
        except ValidationError as e:
            error_messages.append(str(e))
        # deserialize data into SOLOperationRedelegate
        try:
            instance.actual_instance = SOLOperationRedelegate.from_json(json_str)
            match += 1
        except ValidationError as e:
            error_messages.append(str(e))
        # deserialize data into SOLOperationSplit
        try:
            instance.actual_instance = SOLOperationSplit.from_json(json_str)
            match += 1
        except ValidationError as e:
            error_messages.append(str(e))
        # deserialize data into SOLOperationWithdraw
        try:
            instance.actual_instance = SOLOperationWithdraw.from_json(json_str)
            match += 1
        except ValidationError as e:
            error_messages.append(str(e))
        # deserialize data into SOLOperationMerge
        try:
            instance.actual_instance = SOLOperationMerge.from_json(json_str)
            match += 1
        except ValidationError 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 GetSolOperations200ResponseDataInner with oneOf schemas: SOLOperationCreateAccount, SOLOperationCreateAccountWithSeed, SOLOperationDeactivate, SOLOperationDelegate, SOLOperationMerge, SOLOperationRedelegate, SOLOperationSplit, SOLOperationWithdraw. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into GetSolOperations200ResponseDataInner with oneOf schemas: SOLOperationCreateAccount, SOLOperationCreateAccountWithSeed, SOLOperationDeactivate, SOLOperationDelegate, SOLOperationMerge, SOLOperationRedelegate, SOLOperationSplit, SOLOperationWithdraw. 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())

