# 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 pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.model_deployment_info import ModelDeploymentInfo
from mixpeek.models.model_resource_requirements import ModelResourceRequirements
from typing import Optional, Set
from typing_extensions import Self

class CustomModelDocument(BaseModel):
    """
    Custom model document stored in MongoDB.
    """ # noqa: E501
    model_id: StrictStr = Field(description="Unique model identifier")
    namespace_id: StrictStr = Field(description="Owner namespace ID")
    name: StrictStr = Field(description="Model name")
    version: StrictStr = Field(description="Model version")
    model_archive_url: StrictStr = Field(description="S3 URL to model archive")
    model_format: StrictStr = Field(description="Model format/framework")
    model_hash: StrictStr = Field(description="SHA256 hash of model file")
    deployed: Optional[StrictBool] = Field(default=False, description="Whether model is deployed")
    deployment_info: Optional[ModelDeploymentInfo] = Field(default=None, description="Deployment details")
    framework: Optional[StrictStr] = Field(default=None, description="ML framework (e.g., sentence-transformers)")
    task_type: Optional[StrictStr] = Field(default=None, description="Task type (e.g., embedding, classification)")
    input_schema: Optional[Dict[str, Any]] = Field(default=None, description="Input schema JSON")
    output_schema: Optional[Dict[str, Any]] = Field(default=None, description="Output schema JSON")
    resource_requirements: Optional[ModelResourceRequirements] = Field(default=None, description="Resource requirements for deployment")
    created_at: Optional[datetime] = Field(default=None, description="Creation timestamp")
    updated_at: Optional[datetime] = Field(default=None, description="Last update timestamp")
    __properties: ClassVar[List[str]] = ["model_id", "namespace_id", "name", "version", "model_archive_url", "model_format", "model_hash", "deployed", "deployment_info", "framework", "task_type", "input_schema", "output_schema", "resource_requirements", "created_at", "updated_at"]

    @field_validator('model_format')
    def model_format_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['safetensors', 'onnx', 'pytorch', 'huggingface']):
            raise ValueError("must be one of enum values ('safetensors', 'onnx', 'pytorch', 'huggingface')")
        return value

    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 CustomModelDocument 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.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of deployment_info
        if self.deployment_info:
            _dict['deployment_info'] = self.deployment_info.to_dict()
        # override the default output from pydantic by calling `to_dict()` of resource_requirements
        if self.resource_requirements:
            _dict['resource_requirements'] = self.resource_requirements.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "model_id": obj.get("model_id"),
            "namespace_id": obj.get("namespace_id"),
            "name": obj.get("name"),
            "version": obj.get("version"),
            "model_archive_url": obj.get("model_archive_url"),
            "model_format": obj.get("model_format"),
            "model_hash": obj.get("model_hash"),
            "deployed": obj.get("deployed") if obj.get("deployed") is not None else False,
            "deployment_info": ModelDeploymentInfo.from_dict(obj["deployment_info"]) if obj.get("deployment_info") is not None else None,
            "framework": obj.get("framework"),
            "task_type": obj.get("task_type"),
            "input_schema": obj.get("input_schema"),
            "output_schema": obj.get("output_schema"),
            "resource_requirements": ModelResourceRequirements.from_dict(obj["resource_requirements"]) if obj.get("resource_requirements") is not None else None,
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


