# 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 Optional

from truefoundry.pydantic_v1 import (
    BaseModel,
    Field,
    StrictStr,
    conlist,
    constr,
    validator,
)


class Agent(BaseModel):
    """
    Agent artifact.  # noqa: E501
    """

    type: Optional[StrictStr] = "agent"
    name: constr(strict=True) = Field(
        default=..., description="Names cannot repeat accross agent +uiType=Hidden"
    )
    available_tools: conlist(constr(strict=True, min_length=1)) = Field(
        default=..., description="+sort=30 +uiType=Hidden"
    )
    goal: constr(strict=True, max_length=128, min_length=1) = Field(
        default=..., description="+sort=10 +uiType=TextArea"
    )
    instruction: constr(strict=True, max_length=2620, min_length=1) = Field(
        default=...,
        description='`instruction` is the system prompt for now. (2.5 * 1024) +sort=20 +uiType=AgentInstructions +uiProps={"helpText":"Use the syntax ${Tool FQN} to reference a tool, and ${AGENT FQN} to reference another agent"}',
    )
    model_id: constr(strict=True, min_length=1) = Field(
        default=...,
        description='+sort=40 +uiType=EnabledModelSelector +uiProps={"searchable":true,"modelType":"chat","providerType":"openai"}',
    )
    __properties = [
        "type",
        "name",
        "available_tools",
        "goal",
        "instruction",
        "model_id",
    ]

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

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

    @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\-]{1,30}[a-zA-Z0-9]$", value):
            raise ValueError(
                r"must validate the regular expression /^[a-zA-Z][a-zA-Z0-9\-]{1,30}[a-zA-Z0-9]$/"
            )
        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) -> Agent:
        """Create an instance of Agent 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)
        return _dict

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

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

        _obj = Agent.parse_obj(
            {
                "type": obj.get("type") if obj.get("type") is not None else "agent",
                "name": obj.get("name"),
                "available_tools": obj.get("available_tools"),
                "goal": obj.get("goal"),
                "instruction": obj.get("instruction"),
                "model_id": obj.get("model_id"),
            }
        )
        return _obj
