# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
from inspect import getfullargspec
import json
import pprint
import re  # noqa: F401
from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator
from typing import Any, Dict, Optional
from mixpeek.models.agglomerative_params import AgglomerativeParams
from mixpeek.models.dbscan_params import DBSCANParams
from mixpeek.models.gaussian_mixture_params import GaussianMixtureParams
from mixpeek.models.hdbscan_params import HDBSCANParams
from mixpeek.models.k_means_params import KMeansParams
from mixpeek.models.mean_shift_params import MeanShiftParams
from mixpeek.models.optics_params import OPTICSParams
from mixpeek.models.spectral_params import SpectralParams
from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict
from typing_extensions import Literal, Self
from pydantic import Field

ALGORITHMPARAMS_ANY_OF_SCHEMAS = ["AgglomerativeParams", "DBSCANParams", "GaussianMixtureParams", "HDBSCANParams", "KMeansParams", "MeanShiftParams", "OPTICSParams", "SpectralParams", "object"]

class AlgorithmParams(BaseModel):
    """
    Algorithm-specific parameters
    """

    # data type: KMeansParams
    anyof_schema_1_validator: Optional[KMeansParams] = None
    # data type: DBSCANParams
    anyof_schema_2_validator: Optional[DBSCANParams] = None
    # data type: HDBSCANParams
    anyof_schema_3_validator: Optional[HDBSCANParams] = None
    # data type: AgglomerativeParams
    anyof_schema_4_validator: Optional[AgglomerativeParams] = None
    # data type: SpectralParams
    anyof_schema_5_validator: Optional[SpectralParams] = None
    # data type: GaussianMixtureParams
    anyof_schema_6_validator: Optional[GaussianMixtureParams] = None
    # data type: MeanShiftParams
    anyof_schema_7_validator: Optional[MeanShiftParams] = None
    # data type: OPTICSParams
    anyof_schema_8_validator: Optional[OPTICSParams] = None
    # data type: object
    anyof_schema_9_validator: Optional[Dict[str, Any]] = None
    if TYPE_CHECKING:
        actual_instance: Optional[Union[AgglomerativeParams, DBSCANParams, GaussianMixtureParams, HDBSCANParams, KMeansParams, MeanShiftParams, OPTICSParams, SpectralParams, object]] = None
    else:
        actual_instance: Any = None
    any_of_schemas: Set[str] = { "AgglomerativeParams", "DBSCANParams", "GaussianMixtureParams", "HDBSCANParams", "KMeansParams", "MeanShiftParams", "OPTICSParams", "SpectralParams", "object" }

    model_config = {
        "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_anyof(cls, v):
        instance = AlgorithmParams.model_construct()
        error_messages = []
        # validate data type: KMeansParams
        if not isinstance(v, KMeansParams):
            error_messages.append(f"Error! Input type `{type(v)}` is not `KMeansParams`")
        else:
            return v

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

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

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

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

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

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

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

        # validate data type: object
        try:
            instance.anyof_schema_9_validator = v
            return v
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        if error_messages:
            # no match
            raise ValueError("No match found when setting the actual_instance in AlgorithmParams with anyOf schemas: AgglomerativeParams, DBSCANParams, GaussianMixtureParams, HDBSCANParams, KMeansParams, MeanShiftParams, OPTICSParams, SpectralParams, object. Details: " + ", ".join(error_messages))
        else:
            return v

    @classmethod
    def from_dict(cls, obj: 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 = []
        # anyof_schema_1_validator: Optional[KMeansParams] = None
        try:
            instance.actual_instance = KMeansParams.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_2_validator: Optional[DBSCANParams] = None
        try:
            instance.actual_instance = DBSCANParams.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_3_validator: Optional[HDBSCANParams] = None
        try:
            instance.actual_instance = HDBSCANParams.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_4_validator: Optional[AgglomerativeParams] = None
        try:
            instance.actual_instance = AgglomerativeParams.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_5_validator: Optional[SpectralParams] = None
        try:
            instance.actual_instance = SpectralParams.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_6_validator: Optional[GaussianMixtureParams] = None
        try:
            instance.actual_instance = GaussianMixtureParams.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_7_validator: Optional[MeanShiftParams] = None
        try:
            instance.actual_instance = MeanShiftParams.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_8_validator: Optional[OPTICSParams] = None
        try:
            instance.actual_instance = OPTICSParams.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # deserialize data into object
        try:
            # validation
            instance.anyof_schema_9_validator = json.loads(json_str)
            # assign value to actual_instance
            instance.actual_instance = instance.anyof_schema_9_validator
            return instance
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))

        if error_messages:
            # no match
            raise ValueError("No match found when deserializing the JSON string into AlgorithmParams with anyOf schemas: AgglomerativeParams, DBSCANParams, GaussianMixtureParams, HDBSCANParams, KMeansParams, MeanShiftParams, OPTICSParams, SpectralParams, object. 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], AgglomerativeParams, DBSCANParams, GaussianMixtureParams, HDBSCANParams, KMeansParams, MeanShiftParams, OPTICSParams, SpectralParams, object]]:
        """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:
            return self.actual_instance

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


