# 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: 0.81.1
    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.box_config import BoxConfig
from mixpeek.models.google_drive_config import GoogleDriveConfig
from mixpeek.models.httpapi_config import HTTPAPIConfig
from mixpeek.models.instagram_config import InstagramConfig
from mixpeek.models.postgre_sql_config import PostgreSQLConfig
from mixpeek.models.rss_config import RSSConfig
from mixpeek.models.s3_config import S3Config
from mixpeek.models.share_point_config import SharePointConfig
from mixpeek.models.snowflake_config import SnowflakeConfig
from mixpeek.models.tigris_config import TigrisConfig
from mixpeek.models.tik_tok_config import TikTokConfig
from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict
from typing_extensions import Literal, Self
from pydantic import Field

PROVIDERCONFIG_ANY_OF_SCHEMAS = ["BoxConfig", "Dict[str, object]", "GoogleDriveConfig", "HTTPAPIConfig", "InstagramConfig", "PostgreSQLConfig", "RSSConfig", "S3Config", "SharePointConfig", "SnowflakeConfig", "TigrisConfig", "TikTokConfig"]

class ProviderConfig(BaseModel):
    """
    REQUIRED. Provider-specific configuration payload including credentials. Type depends on provider_type (GoogleDriveConfig, S3Config, etc.). SECURITY: Sensitive credential fields are encrypted at rest via MongoDB client-side field level encryption (CSFLE). Credentials never appear in API responses or logs. See provider_configs.py for detailed schemas.
    """

    # data type: GoogleDriveConfig
    anyof_schema_1_validator: Optional[GoogleDriveConfig] = None
    # data type: S3Config
    anyof_schema_2_validator: Optional[S3Config] = None
    # data type: SnowflakeConfig
    anyof_schema_3_validator: Optional[SnowflakeConfig] = None
    # data type: SharePointConfig
    anyof_schema_4_validator: Optional[SharePointConfig] = None
    # data type: TigrisConfig
    anyof_schema_5_validator: Optional[TigrisConfig] = None
    # data type: PostgreSQLConfig
    anyof_schema_6_validator: Optional[PostgreSQLConfig] = None
    # data type: InstagramConfig
    anyof_schema_7_validator: Optional[InstagramConfig] = None
    # data type: TikTokConfig
    anyof_schema_8_validator: Optional[TikTokConfig] = None
    # data type: RSSConfig
    anyof_schema_9_validator: Optional[RSSConfig] = None
    # data type: HTTPAPIConfig
    anyof_schema_10_validator: Optional[HTTPAPIConfig] = None
    # data type: BoxConfig
    anyof_schema_11_validator: Optional[BoxConfig] = None
    # data type: Dict[str, object]
    anyof_schema_12_validator: Optional[Dict[str, Any]] = None
    if TYPE_CHECKING:
        actual_instance: Optional[Union[BoxConfig, Dict[str, object], GoogleDriveConfig, HTTPAPIConfig, InstagramConfig, PostgreSQLConfig, RSSConfig, S3Config, SharePointConfig, SnowflakeConfig, TigrisConfig, TikTokConfig]] = None
    else:
        actual_instance: Any = None
    any_of_schemas: Set[str] = { "BoxConfig", "Dict[str, object]", "GoogleDriveConfig", "HTTPAPIConfig", "InstagramConfig", "PostgreSQLConfig", "RSSConfig", "S3Config", "SharePointConfig", "SnowflakeConfig", "TigrisConfig", "TikTokConfig" }

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

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

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

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

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

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

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

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

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

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

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

        # validate data type: Dict[str, object]
        try:
            instance.anyof_schema_12_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 ProviderConfig with anyOf schemas: BoxConfig, Dict[str, object], GoogleDriveConfig, HTTPAPIConfig, InstagramConfig, PostgreSQLConfig, RSSConfig, S3Config, SharePointConfig, SnowflakeConfig, TigrisConfig, TikTokConfig. 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[GoogleDriveConfig] = None
        try:
            instance.actual_instance = GoogleDriveConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_2_validator: Optional[S3Config] = None
        try:
            instance.actual_instance = S3Config.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_3_validator: Optional[SnowflakeConfig] = None
        try:
            instance.actual_instance = SnowflakeConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_4_validator: Optional[SharePointConfig] = None
        try:
            instance.actual_instance = SharePointConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_5_validator: Optional[TigrisConfig] = None
        try:
            instance.actual_instance = TigrisConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_6_validator: Optional[PostgreSQLConfig] = None
        try:
            instance.actual_instance = PostgreSQLConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_7_validator: Optional[InstagramConfig] = None
        try:
            instance.actual_instance = InstagramConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_8_validator: Optional[TikTokConfig] = None
        try:
            instance.actual_instance = TikTokConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_9_validator: Optional[RSSConfig] = None
        try:
            instance.actual_instance = RSSConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_10_validator: Optional[HTTPAPIConfig] = None
        try:
            instance.actual_instance = HTTPAPIConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # anyof_schema_11_validator: Optional[BoxConfig] = None
        try:
            instance.actual_instance = BoxConfig.from_json(json_str)
            return instance
        except (ValidationError, ValueError) as e:
             error_messages.append(str(e))
        # deserialize data into Dict[str, object]
        try:
            # validation
            instance.anyof_schema_12_validator = json.loads(json_str)
            # assign value to actual_instance
            instance.actual_instance = instance.anyof_schema_12_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 ProviderConfig with anyOf schemas: BoxConfig, Dict[str, object], GoogleDriveConfig, HTTPAPIConfig, InstagramConfig, PostgreSQLConfig, RSSConfig, S3Config, SharePointConfig, SnowflakeConfig, TigrisConfig, TikTokConfig. 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], BoxConfig, Dict[str, object], GoogleDriveConfig, HTTPAPIConfig, InstagramConfig, PostgreSQLConfig, RSSConfig, S3Config, SharePointConfig, SnowflakeConfig, TigrisConfig, TikTokConfig]]:
        """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())


