# 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
import json
import pprint
from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator
from typing import Any, List, Optional
from mixpeek.models.column_source import ColumnSource
from mixpeek.models.constant_source import ConstantSource
from mixpeek.models.drive_property_source import DrivePropertySource
from mixpeek.models.file_source import FileSource
from mixpeek.models.filename_regex_source import FilenameRegexSource
from mixpeek.models.folder_path_source import FolderPathSource
from mixpeek.models.s3_metadata_source import S3MetadataSource
from mixpeek.models.s3_tag_source import S3TagSource
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

SOURCE_ONE_OF_SCHEMAS = ["ColumnSource", "ConstantSource", "DrivePropertySource", "FileSource", "FilenameRegexSource", "FolderPathSource", "S3MetadataSource", "S3TagSource"]

class Source(BaseModel):
    """
    Source extractor defining where to get the blob content or URL. Use 'file' for the synced file itself (most common). Use 'column' for database URL columns pointing to external content. Use 'metadata' for S3 metadata containing URLs.
    """
    # data type: S3TagSource
    oneof_schema_1_validator: Optional[S3TagSource] = None
    # data type: S3MetadataSource
    oneof_schema_2_validator: Optional[S3MetadataSource] = None
    # data type: FilenameRegexSource
    oneof_schema_3_validator: Optional[FilenameRegexSource] = None
    # data type: ColumnSource
    oneof_schema_4_validator: Optional[ColumnSource] = None
    # data type: DrivePropertySource
    oneof_schema_5_validator: Optional[DrivePropertySource] = None
    # data type: FolderPathSource
    oneof_schema_6_validator: Optional[FolderPathSource] = None
    # data type: FileSource
    oneof_schema_7_validator: Optional[FileSource] = None
    # data type: ConstantSource
    oneof_schema_8_validator: Optional[ConstantSource] = None
    actual_instance: Optional[Union[ColumnSource, ConstantSource, DrivePropertySource, FileSource, FilenameRegexSource, FolderPathSource, S3MetadataSource, S3TagSource]] = None
    one_of_schemas: Set[str] = { "ColumnSource", "ConstantSource", "DrivePropertySource", "FileSource", "FilenameRegexSource", "FolderPathSource", "S3MetadataSource", "S3TagSource" }

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


    discriminator_value_class_map: Dict[str, str] = {
    }

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


