# coding: utf-8

"""
    Vantage API

    This is a the API to interact with Vantage Discovery, the amazing Semantic Search Platform in the world.  We enable developers to build magical discovery experiences into their products and websites.  Some useful links: - [TODO: Semantic Search Guide: What Is It And Why Does It Matter?](https://www.bloomreach.com/en/blog/2019/semantic-search-explained-in-5-minutes)

    The version of the OpenAPI document: v1.1.2
    Contact: devrel@vantagediscovery.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
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional

from pydantic import (
    BaseModel,
    Field,
    StrictBool,
    StrictInt,
    StrictStr,
    field_validator,
)

from vantage_sdk.core.http.models.secondary_external_account import (
    SecondaryExternalAccount,
)


try:
    from typing import Self
except ImportError:
    from typing_extensions import Self


class Collection(BaseModel):
    """
    Collection
    """  # noqa: E501

    collection_created_time: Optional[StrictStr] = None
    collection_status: Optional[StrictStr] = None
    collection_state: Optional[StrictStr] = None
    collection_id: Optional[StrictStr] = Field(
        default=None,
        description="Immutable.  Unique identifier within an account, 3 to 36 characters long with only lower case letters, numeric digits and \"-\"",
    )
    user_provided_embeddings: Optional[StrictBool] = Field(
        default=False,
        description="Ignore llm field will provide own embeddings for both ingest and search",
    )
    llm: Optional[StrictStr] = None
    llm_provider: Optional[StrictStr] = None
    llm_secret: Optional[StrictStr] = None
    external_url: Optional[StrictStr] = None
    embeddings_dimension: Optional[StrictInt] = Field(
        default=None,
        description="The dimensionality or vector size of the embeddings.  Applies to both user provided embeddings and vantage managed embeddings.",
    )
    external_key_id: Optional[StrictStr] = Field(
        default=None,
        description="The external key, for the llm_provider to use for the collection",
    )
    secondary_external_accounts: Optional[
        List[SecondaryExternalAccount]
    ] = None
    collection_name: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "collection_created_time",
        "collection_status",
        "collection_state",
        "collection_id",
        "user_provided_embeddings",
        "llm",
        "llm_provider",
        "llm_secret",
        "external_url",
        "embeddings_dimension",
        "external_key_id",
        "secondary_external_accounts",
        "collection_name",
    ]

    @field_validator('collection_status')
    def collection_status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in (
            'Pending',
            'Indexing',
            'Online',
            'Degraded',
            'Offline',
            'Empty',
        ):
            raise ValueError(
                "must be one of enum values ('Pending', 'Indexing', 'Online', 'Degraded', 'Offline', 'Empty')"
            )
        return value

    @field_validator('collection_state')
    def collection_state_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ('Active', 'Standby', 'Deleted'):
            raise ValueError(
                "must be one of enum values ('Active', 'Standby', 'Deleted')"
            )
        return value

    @field_validator('llm_provider')
    def llm_provider_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ('Hugging', 'OpenAI'):
            raise ValueError(
                "must be one of enum values ('Hugging', 'OpenAI')"
            )
        return value

    model_config = {
        "populate_by_name": True,
        "validate_assignment": True,
        "protected_namespaces": (),
    }

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Create an instance of Collection from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
                "collection_created_time",
                "collection_status",
                "collection_state",
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in secondary_external_accounts (list)
        _items = []
        if self.secondary_external_accounts:
            for _item in self.secondary_external_accounts:
                if _item:
                    _items.append(_item.to_dict())
            _dict['secondary_external_accounts'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of Collection from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate(
            {
                "collection_created_time": obj.get("collection_created_time"),
                "collection_status": obj.get("collection_status"),
                "collection_state": obj.get("collection_state"),
                "collection_id": obj.get("collection_id"),
                "user_provided_embeddings": obj.get("user_provided_embeddings")
                if obj.get("user_provided_embeddings") is not None
                else False,
                "llm": obj.get("llm"),
                "llm_provider": obj.get("llm_provider"),
                "llm_secret": obj.get("llm_secret"),
                "external_url": obj.get("external_url"),
                "embeddings_dimension": obj.get("embeddings_dimension"),
                "external_key_id": obj.get("external_key_id"),
                "secondary_external_accounts": [
                    SecondaryExternalAccount.from_dict(_item)
                    for _item in obj.get("secondary_external_accounts")
                ]
                if obj.get("secondary_external_accounts") is not None
                else None,
                "collection_name": obj.get("collection_name"),
            }
        )
        return _obj
