# coding: utf-8

"""
    Coinbase Developer Platform APIs

    The Coinbase Developer Platform APIs - leading the world's transition onchain.

    The version of the OpenAPI document: 2.0.0
    Contact: cdp@coinbase.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 cdp.openapi_client.models.mint_address_criterion import MintAddressCriterion
from cdp.openapi_client.models.program_id_criterion import ProgramIdCriterion
from cdp.openapi_client.models.sol_address_criterion import SolAddressCriterion
from cdp.openapi_client.models.sol_data_criterion import SolDataCriterion
from cdp.openapi_client.models.sol_value_criterion import SolValueCriterion
from cdp.openapi_client.models.spl_address_criterion import SplAddressCriterion
from cdp.openapi_client.models.spl_value_criterion import SplValueCriterion
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

SIGNSOLTRANSACTIONCRITERIAINNER_ONE_OF_SCHEMAS = ["MintAddressCriterion", "ProgramIdCriterion", "SolAddressCriterion", "SolDataCriterion", "SolValueCriterion", "SplAddressCriterion", "SplValueCriterion"]

class SignSolTransactionCriteriaInner(BaseModel):
    """
    SignSolTransactionCriteriaInner
    """
    # data type: SolAddressCriterion
    oneof_schema_1_validator: Optional[SolAddressCriterion] = None
    # data type: SolValueCriterion
    oneof_schema_2_validator: Optional[SolValueCriterion] = None
    # data type: SplAddressCriterion
    oneof_schema_3_validator: Optional[SplAddressCriterion] = None
    # data type: SplValueCriterion
    oneof_schema_4_validator: Optional[SplValueCriterion] = None
    # data type: MintAddressCriterion
    oneof_schema_5_validator: Optional[MintAddressCriterion] = None
    # data type: SolDataCriterion
    oneof_schema_6_validator: Optional[SolDataCriterion] = None
    # data type: ProgramIdCriterion
    oneof_schema_7_validator: Optional[ProgramIdCriterion] = None
    actual_instance: Optional[Union[MintAddressCriterion, ProgramIdCriterion, SolAddressCriterion, SolDataCriterion, SolValueCriterion, SplAddressCriterion, SplValueCriterion]] = None
    one_of_schemas: Set[str] = { "MintAddressCriterion", "ProgramIdCriterion", "SolAddressCriterion", "SolDataCriterion", "SolValueCriterion", "SplAddressCriterion", "SplValueCriterion" }

    model_config = ConfigDict(
        validate_assignment=True,
        protected_namespaces=(),
    )


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


