# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 3.54.3-ai-plus
    Generated by OpenAPI Generator (https://openapi-generator.tech)

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


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from iblai.models.retriever_document_embedding_access import RetrieverDocumentEmbeddingAccess
from iblai.models.retriever_document_embedding_training_status import RetrieverDocumentEmbeddingTrainingStatus
from typing import Optional, Set
from typing_extensions import Self

class RetrieverDocumentEmbedding(BaseModel):
    """
    RetrieverDocumentEmbedding
    """ # noqa: E501
    id: StrictInt
    metadata: Optional[Any] = None
    document_name: Optional[StrictStr] = None
    document_type: Optional[StrictStr] = None
    training_status: Optional[RetrieverDocumentEmbeddingTrainingStatus] = None
    pathway: StrictStr
    url: Optional[StrictStr] = None
    tokens: Optional[StrictInt] = None
    platform_key: StrictStr
    is_trained: Optional[StrictBool] = None
    access: Optional[RetrieverDocumentEmbeddingAccess] = None
    __properties: ClassVar[List[str]] = ["id", "metadata", "document_name", "document_type", "training_status", "pathway", "url", "tokens", "platform_key", "is_trained", "access"]

    model_config = ConfigDict(
        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) -> Optional[Self]:
        """Create an instance of RetrieverDocumentEmbedding 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.
        """
        excluded_fields: Set[str] = set([
            "id",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of training_status
        if self.training_status:
            _dict['training_status'] = self.training_status.to_dict()
        # override the default output from pydantic by calling `to_dict()` of access
        if self.access:
            _dict['access'] = self.access.to_dict()
        # set to None if metadata (nullable) is None
        # and model_fields_set contains the field
        if self.metadata is None and "metadata" in self.model_fields_set:
            _dict['metadata'] = None

        # set to None if document_name (nullable) is None
        # and model_fields_set contains the field
        if self.document_name is None and "document_name" in self.model_fields_set:
            _dict['document_name'] = None

        # set to None if document_type (nullable) is None
        # and model_fields_set contains the field
        if self.document_type is None and "document_type" in self.model_fields_set:
            _dict['document_type'] = None

        # set to None if training_status (nullable) is None
        # and model_fields_set contains the field
        if self.training_status is None and "training_status" in self.model_fields_set:
            _dict['training_status'] = None

        # set to None if url (nullable) is None
        # and model_fields_set contains the field
        if self.url is None and "url" in self.model_fields_set:
            _dict['url'] = None

        # set to None if tokens (nullable) is None
        # and model_fields_set contains the field
        if self.tokens is None and "tokens" in self.model_fields_set:
            _dict['tokens'] = None

        # set to None if access (nullable) is None
        # and model_fields_set contains the field
        if self.access is None and "access" in self.model_fields_set:
            _dict['access'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of RetrieverDocumentEmbedding from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "metadata": obj.get("metadata"),
            "document_name": obj.get("document_name"),
            "document_type": obj.get("document_type"),
            "training_status": RetrieverDocumentEmbeddingTrainingStatus.from_dict(obj["training_status"]) if obj.get("training_status") is not None else None,
            "pathway": obj.get("pathway"),
            "url": obj.get("url"),
            "tokens": obj.get("tokens"),
            "platform_key": obj.get("platform_key"),
            "is_trained": obj.get("is_trained"),
            "access": RetrieverDocumentEmbeddingAccess.from_dict(obj["access"]) if obj.get("access") is not None else None
        })
        return _obj


