# 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 pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.model_resource_requirements import ModelResourceRequirements
from typing import Optional, Set
from typing_extensions import Self

class CreateModelUploadRequest(BaseModel):
    """
    Request to generate a presigned URL for model archive upload.  This is step 1 of the presigned URL workflow: 1. POST /models/uploads → Returns presigned_url + upload_id 2. PUT presigned_url with model archive (client uploads directly to S3) 3. POST /models/uploads/{upload_id}/confirm → Validates and creates model  Requirements:     - name: Model name (e.g., 'my_custom_embedder')     - version: Semantic version (e.g., '1.0.0')     - model_format: Format of the model weights     - file_size_bytes: Expected archive size for quota validation
    """ # noqa: E501
    name: Annotated[str, Field(strict=True)] = Field(description="Model name (alphanumeric with underscores, no spaces)")
    version: Annotated[str, Field(strict=True)] = Field(description="Semantic version string")
    model_format: StrictStr = Field(description="Format of the model weights")
    description: Optional[Annotated[str, Field(strict=True, max_length=500)]] = Field(default=None, description="Optional description of the model")
    file_size_bytes: Optional[Annotated[int, Field(le=5368709120, strict=True)]] = Field(default=None, description="Expected file size in bytes for quota validation")
    presigned_url_expiration: Optional[Annotated[int, Field(le=86400, strict=True, ge=60)]] = Field(default=3600, description="Presigned URL expiration time in seconds (1-24 hours)")
    resource_requirements: Optional[ModelResourceRequirements] = Field(default=None, description="Resource requirements for model deployment")
    framework: Optional[StrictStr] = Field(default=None, description="ML framework (e.g., sentence-transformers, transformers)")
    task_type: Optional[StrictStr] = Field(default=None, description="Task type (e.g., embedding, classification, generation)")
    __properties: ClassVar[List[str]] = ["name", "version", "model_format", "description", "file_size_bytes", "presigned_url_expiration", "resource_requirements", "framework", "task_type"]

    @field_validator('name')
    def name_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[a-zA-Z][a-zA-Z0-9_]{2,63}$", value):
            raise ValueError(r"must validate the regular expression /^[a-zA-Z][a-zA-Z0-9_]{2,63}$/")
        return value

    @field_validator('version')
    def version_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^\d+\.\d+\.\d+$", value):
            raise ValueError(r"must validate the regular expression /^\d+\.\d+\.\d+$/")
        return value

    @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 CreateModelUploadRequest 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 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 CreateModelUploadRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "version": obj.get("version"),
            "model_format": obj.get("model_format"),
            "description": obj.get("description"),
            "file_size_bytes": obj.get("file_size_bytes"),
            "presigned_url_expiration": obj.get("presigned_url_expiration") if obj.get("presigned_url_expiration") is not None else 3600,
            "resource_requirements": ModelResourceRequirements.from_dict(obj["resource_requirements"]) if obj.get("resource_requirements") is not None else None,
            "framework": obj.get("framework"),
            "task_type": obj.get("task_type")
        })
        return _obj


