# Copyright 2025 WhoMeta Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Common primitives for Unified Agent Protocol models.

Generated by WhoMeta Unified Agent Protocol SDK
"""
from __future__ import annotations

from enum import Enum
from typing import Any, Dict, Optional

from pydantic import BaseModel, Field


class Role(str, Enum):
    """Channel role of a message or tool."""

    USER = "user"
    ASSISTANT = "assistant"
    SYSTEM = "system"
    TOOL = "tool"


class Trigger(BaseModel):
    """Defines when a tool or agent should be invoked."""

    type: str = Field(..., description="Trigger type (e.g. text, event, function)")
    pattern: Optional[str] = Field(
        None, description="Regex or glob pattern for textual triggers"
    )
    event_name: Optional[str] = Field(None, description="Identifier for event triggers")
    description: Optional[str] = None
    metadata: Dict[str, Any] = Field(default_factory=dict)

    class Config:
        extra = "allow"
        schema_extra = {
            "example": {
                "type": "text",
                "pattern": "^/weather",
                "description": "Invoked when the user asks for weather",
            }
        }


class UIConfig(BaseModel):
    """Optional UI hints for rendering a tool in front-ends."""

    label: str = Field(..., description="Human-readable label")
    description: Optional[str] = None
    icon: Optional[str] = Field(None, description="Icon name or URL")
    group: Optional[str] = Field(None, description="Logical grouping (e.g. sidebar section)")
    color: Optional[str] = None
    order: Optional[int] = Field(None, description="Ordering weight")
    extra: Dict[str, Any] = Field(default_factory=dict, description="Additional UI hints")

    class Config:
        extra = "allow"
        schema_extra = {
            "example": {
                "label": "Get Weather",
                "icon": "mdi:weather-partly-cloudy",
                "color": "#00aaff",
            }
        }
