# 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_aws_credentials import ServingAWSCredentials
from cloudera.ai.inference.models.serving_gcp_credentials import ServingGCPCredentials
from typing import Optional, Set
from typing_extensions import Self

class ServingThirdPartySource(BaseModel):
    """
    Source for third-party LLM API endpoints (e.g., OpenAI, Azure OpenAI, AWS Bedrock, Gemini)
    """ # noqa: E501
    url: Optional[StrictStr] = Field(default=None, description="Target base URL of the external LLM API (e.g., \"https://api.openai.com\")")
    model: Optional[StrictStr] = Field(default=None, description="Model identifier (e.g., \"gpt-4o-mini\" for OpenAI, deployment name for Azure)")
    provider_type: Optional[StrictStr] = Field(default=None, description="Provider type determines schema translation, auth mechanism, and token counting")
    api_key: Optional[StrictStr] = Field(default=None, description="API key for OpenAI, Azure OpenAI")
    aws_credentials: Optional[ServingAWSCredentials] = Field(default=None, description="AWS credentials for Bedrock")
    gcp_credentials: Optional[ServingGCPCredentials] = Field(default=None, description="GCP credentials for Gemini (Vertex AI)")
    api_version: Optional[StrictStr] = Field(default=None, description="API version (required for Azure OpenAI, e.g., \"2024-10-21\")")
    path_prefix: Optional[StrictStr] = Field(default=None, description="Optional path prefix for the provider API (e.g., \"/v1beta/openai\" for Gemini)")
    __properties: ClassVar[List[str]] = ["url", "model", "provider_type", "api_key", "aws_credentials", "gcp_credentials", "api_version", "path_prefix"]

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

        if value not in set(['THIRD_PARTY_PROVIDER_UNSPECIFIED', 'OPENAI', 'AZURE_OPENAI', 'AWS_BEDROCK', 'GEMINI']):
            raise ValueError("must be one of enum values ('THIRD_PARTY_PROVIDER_UNSPECIFIED', 'OPENAI', 'AZURE_OPENAI', 'AWS_BEDROCK', 'GEMINI')")
        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 ServingThirdPartySource 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 aws_credentials
        if self.aws_credentials:
            _dict['aws_credentials'] = self.aws_credentials.to_dict()
        # override the default output from pydantic by calling `to_dict()` of gcp_credentials
        if self.gcp_credentials:
            _dict['gcp_credentials'] = self.gcp_credentials.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "url": obj.get("url"),
            "model": obj.get("model"),
            "provider_type": obj.get("provider_type"),
            "api_key": obj.get("api_key"),
            "aws_credentials": ServingAWSCredentials.from_dict(obj["aws_credentials"]) if obj.get("aws_credentials") is not None else None,
            "gcp_credentials": ServingGCPCredentials.from_dict(obj["gcp_credentials"]) if obj.get("gcp_credentials") is not None else None,
            "api_version": obj.get("api_version"),
            "path_prefix": obj.get("path_prefix")
        })
        return _obj


