# coding: utf-8

"""
    Cloudera AI Inference

    CML Serving :: Install and manage CML Serving workloads.

    The version of the OpenAPI document: v1alpha1
    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 cloudera.ai.inference.models.serving_autoscaling import ServingAutoscaling
from cloudera.ai.inference.models.serving_environment_variable import ServingEnvironmentVariable
from cloudera.ai.inference.models.serving_inference_logging_config import ServingInferenceLoggingConfig
from cloudera.ai.inference.models.serving_label import ServingLabel
from cloudera.ai.inference.models.serving_model_source import ServingModelSource
from cloudera.ai.inference.models.serving_rate_limit_config import ServingRateLimitConfig
from cloudera.ai.inference.models.serving_resources import ServingResources
from cloudera.ai.inference.models.serving_vllm_engine_args import ServingVLLMEngineArgs
from typing import Optional, Set
from typing_extensions import Self

class ServingDeployEndpointRequest(BaseModel):
    """
    ServingDeployEndpointRequest
    """ # noqa: E501
    namespace: Optional[StrictStr] = Field(default=None, description="the namespace that the endpoint resides in")
    name: Optional[StrictStr] = Field(default=None, description="the name of the endpoint.  Can consist of alphanumerics, spaces, dashes but must not exceed 36 characters")
    source: Optional[ServingModelSource] = Field(default=None, description="the source of the endpoint")
    resources: Optional[ServingResources] = Field(default=None, description="the resource requirements for the given endpoint replica")
    autoscaling: Optional[ServingAutoscaling] = Field(default=None, description="the autoscaling configurations for the given endpoint")
    labels: Optional[List[ServingLabel]] = Field(default=None, description="labels to be added to the given endpoint")
    description: Optional[StrictStr] = Field(default=None, description="a description of the endpoint")
    traffic: Optional[StrictStr] = Field(default=None, description="the traffic routed to this revision.  This is always set to 100 for endpoint deployments")
    vllm_engine_args: Optional[ServingVLLMEngineArgs] = Field(default=None, description="DEPRECATED (use vllm_args instead): arguments specifically passed into vLLM models")
    instance_type: Optional[StrictStr] = Field(default=None, description="the compute instance type that the model deployment should be scheduled on")
    gpu_type: Optional[StrictStr] = Field(default=None, description="the gpu type, eg A100", alias="gpuType")
    inference_logging_config: Optional[ServingInferenceLoggingConfig] = Field(default=None, description="inference logging configuration to apply to the endpoint")
    ml_user_permission: Optional[StrictStr] = Field(default=None, description="permission to be granted to the mluser group")
    vllm_args: Optional[StrictStr] = Field(default=None, description="arguments specifically passed into vLLM models")
    deployment_mode: Optional[StrictStr] = Field(default=None, description="deployment mode.  Default is KNATIVE")
    environment_variables: Optional[List[ServingEnvironmentVariable]] = Field(default=None, description="environment variables to be added to the endpoint")
    task_override: Optional[StrictStr] = Field(default=None, description="optional task override to specify model task when auto-detection is ambiguous or incorrect")
    rate_limit: Optional[ServingRateLimitConfig] = Field(default=None, description="optional rate limit configuration for the endpoint")
    __properties: ClassVar[List[str]] = ["namespace", "name", "source", "resources", "autoscaling", "labels", "description", "traffic", "vllm_engine_args", "instance_type", "gpuType", "inference_logging_config", "ml_user_permission", "vllm_args", "deployment_mode", "environment_variables", "task_override", "rate_limit"]

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

        if value not in set(['DEPLOYMENT_MODE_UNKNOWN', 'KNATIVE', 'RAW_DEPLOYMENT']):
            raise ValueError("must be one of enum values ('DEPLOYMENT_MODE_UNKNOWN', 'KNATIVE', 'RAW_DEPLOYMENT')")
        return value

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

        if value not in set(['TASK_UNKNOWN', 'INFERENCE', 'TEXT_GENERATION', 'EMBED', 'TEXT_TO_TEXT_GENERATION', 'CLASSIFICATION', 'FILL_MASK', 'RANK', 'SPEECH_TO_TEXT', 'IMAGE_TEXT_TO_TEXT', 'OBJECT_DETECTION', 'TEXT_TO_SPEECH']):
            raise ValueError("must be one of enum values ('TASK_UNKNOWN', 'INFERENCE', 'TEXT_GENERATION', 'EMBED', 'TEXT_TO_TEXT_GENERATION', 'CLASSIFICATION', 'FILL_MASK', 'RANK', 'SPEECH_TO_TEXT', 'IMAGE_TEXT_TO_TEXT', 'OBJECT_DETECTION', 'TEXT_TO_SPEECH')")
        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 ServingDeployEndpointRequest 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 source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of resources
        if self.resources:
            _dict['resources'] = self.resources.to_dict()
        # override the default output from pydantic by calling `to_dict()` of autoscaling
        if self.autoscaling:
            _dict['autoscaling'] = self.autoscaling.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in labels (list)
        _items = []
        if self.labels:
            for _item_labels in self.labels:
                if _item_labels:
                    _items.append(_item_labels.to_dict())
            _dict['labels'] = _items
        # override the default output from pydantic by calling `to_dict()` of vllm_engine_args
        if self.vllm_engine_args:
            _dict['vllm_engine_args'] = self.vllm_engine_args.to_dict()
        # override the default output from pydantic by calling `to_dict()` of inference_logging_config
        if self.inference_logging_config:
            _dict['inference_logging_config'] = self.inference_logging_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in environment_variables (list)
        _items = []
        if self.environment_variables:
            for _item_environment_variables in self.environment_variables:
                if _item_environment_variables:
                    _items.append(_item_environment_variables.to_dict())
            _dict['environment_variables'] = _items
        # override the default output from pydantic by calling `to_dict()` of rate_limit
        if self.rate_limit:
            _dict['rate_limit'] = self.rate_limit.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "namespace": obj.get("namespace"),
            "name": obj.get("name"),
            "source": ServingModelSource.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "resources": ServingResources.from_dict(obj["resources"]) if obj.get("resources") is not None else None,
            "autoscaling": ServingAutoscaling.from_dict(obj["autoscaling"]) if obj.get("autoscaling") is not None else None,
            "labels": [ServingLabel.from_dict(_item) for _item in obj["labels"]] if obj.get("labels") is not None else None,
            "description": obj.get("description"),
            "traffic": obj.get("traffic"),
            "vllm_engine_args": ServingVLLMEngineArgs.from_dict(obj["vllm_engine_args"]) if obj.get("vllm_engine_args") is not None else None,
            "instance_type": obj.get("instance_type"),
            "gpuType": obj.get("gpuType"),
            "inference_logging_config": ServingInferenceLoggingConfig.from_dict(obj["inference_logging_config"]) if obj.get("inference_logging_config") is not None else None,
            "ml_user_permission": obj.get("ml_user_permission"),
            "vllm_args": obj.get("vllm_args"),
            "deployment_mode": obj.get("deployment_mode"),
            "environment_variables": [ServingEnvironmentVariable.from_dict(_item) for _item in obj["environment_variables"]] if obj.get("environment_variables") is not None else None,
            "task_override": obj.get("task_override"),
            "rate_limit": ServingRateLimitConfig.from_dict(obj["rate_limit"]) if obj.get("rate_limit") is not None else None
        })
        return _obj


