# coding: utf-8

"""
FastAPI

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

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

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

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Dict, Optional

from truefoundry.ml.autogen.client.models.chat_prompt_messages_inner import (
    ChatPromptMessagesInner,
)
from truefoundry.ml.autogen.client.models.model_configuration import ModelConfiguration
from truefoundry.pydantic_v1 import (
    BaseModel,
    Field,
    StrictStr,
    conlist,
    constr,
    validator,
)


class ChatPrompt(BaseModel):
    """
    Chat Prompt artifact.  # noqa: E501
    """

    name: constr(strict=True) = Field(
        default=...,
        description="+label=Prompt Name +icon=fa-desktop:#326ce5 +message=Alphanumeric word, may contain '-' with a maximum length of 256 characters +sort=1000 +usage=Name of the Prompt. This uniquely identifies it in the workspace. +docs=The unique name for the prompt, consisting of alphanumeric characters and dashes, max length 100.",
    )
    description: Optional[constr(strict=True, max_length=512, min_length=1)] = Field(
        default=None,
        description="+label=Description +icon=fa-desktop:#326ce5 +message=Description in a maximum of 512 characters +sort=2000 +usage=Description of the prompt +docs=An optional description for the prompt, with a maximum length of 512 characters. +optional",
    )
    model_configuration: ModelConfiguration = Field(...)
    metadata: Dict[str, StrictStr] = Field(
        default=...,
        description="+label=Metadata +icon=fa-info-circle:#326ce5 +message=Additional metadata for the prompt +sort=7000 +usage=Define additional metadata for the prompt +docs=Key-value pairs to store additional metadata related to the prompt.",
    )
    type: Optional[StrictStr] = "chat_prompt"
    messages: conlist(ChatPromptMessagesInner) = Field(
        default=...,
        description="+sort=4000 +usage=Chat completion messages +label=Messages in the chat conversation +message=Chat completion messages +usage=List of messages in the chat conversation, must be non-empty +docs=Messages that define the chat conversation, including system, assistant, and user messages.",
    )
    variables: Optional[Dict[str, StrictStr]] = Field(
        default=None,
        description="+label=Variables +usage=Variables for the chat completion messages to be used in the prompt messages +sort=5000",
    )
    __properties = [
        "name",
        "description",
        "model_configuration",
        "metadata",
        "type",
        "messages",
        "variables",
    ]

    @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-_]{0,254}[a-zA-Z0-9]$", value):
            raise ValueError(
                r"must validate the regular expression /^[a-zA-Z][a-zA-Z0-9-_]{0,254}[a-zA-Z0-9]$/"
            )
        return value

    @validator("type")
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ("chat_prompt",):
            raise ValueError("must be one of enum values ('chat_prompt')")
        return value

    class Config:
        """Pydantic configuration"""

        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> ChatPrompt:
        """Create an instance of ChatPrompt from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True, exclude={}, exclude_none=True)
        # override the default output from truefoundry.pydantic_v1 by calling `to_dict()` of model_configuration
        if self.model_configuration:
            _dict["model_configuration"] = self.model_configuration.to_dict()
        # override the default output from truefoundry.pydantic_v1 by calling `to_dict()` of each item in messages (list)
        _items = []
        if self.messages:
            for _item in self.messages:
                if _item:
                    _items.append(_item.to_dict())
            _dict["messages"] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> ChatPrompt:
        """Create an instance of ChatPrompt from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return ChatPrompt.parse_obj(obj)

        _obj = ChatPrompt.parse_obj(
            {
                "name": obj.get("name"),
                "description": obj.get("description"),
                "model_configuration": ModelConfiguration.from_dict(
                    obj.get("model_configuration")
                )
                if obj.get("model_configuration") is not None
                else None,
                "metadata": obj.get("metadata"),
                "type": obj.get("type")
                if obj.get("type") is not None
                else "chat_prompt",
                "messages": [
                    ChatPromptMessagesInner.from_dict(_item)
                    for _item in obj.get("messages")
                ]
                if obj.get("messages") is not None
                else None,
                "variables": obj.get("variables"),
            }
        )
        return _obj
