using System.Text.Json;
using Codex.Dal.Enums;

namespace Codex.Dal.Entities;

/// <summary>
/// Represents a tool or API integration available to an agent.
/// One-to-many relationship: each agent has its own tool configurations.
/// </summary>
public class AgentTool
{
    /// <summary>
    /// Unique identifier for this tool instance
    /// </summary>
    public Guid Id { get; set; }

    /// <summary>
    /// Foreign key to the owning agent
    /// </summary>
    public Guid AgentId { get; set; }

    /// <summary>
    /// Name of the tool (e.g., "file_reader", "code_executor", "github_api")
    /// </summary>
    public string ToolName { get; set; } = string.Empty;

    /// <summary>
    /// Type of tool
    /// </summary>
    public ToolType Type { get; set; }

    /// <summary>
    /// Tool-specific configuration stored as JSON (e.g., API endpoints, file paths, MCP server URLs)
    /// </summary>
    public JsonDocument? Configuration { get; set; }

    /// <summary>
    /// MCP server URL (if Type is McpServer)
    /// </summary>
    public string? McpServerUrl { get; set; }

    /// <summary>
    /// Encrypted authentication token for MCP server (if required)
    /// </summary>
    public string? McpAuthTokenEncrypted { get; set; }

    /// <summary>
    /// Base URL for REST API (if Type is RestApi)
    /// </summary>
    public string? ApiBaseUrl { get; set; }

    /// <summary>
    /// Encrypted API key for REST API (if required)
    /// </summary>
    public string? ApiKeyEncrypted { get; set; }

    /// <summary>
    /// Whether this tool is enabled for use
    /// </summary>
    public bool IsEnabled { get; set; } = true;

    /// <summary>
    /// When this tool was added to the agent
    /// </summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    // Navigation properties
    /// <summary>
    /// The agent that owns this tool
    /// </summary>
    public Agent Agent { get; set; } = null!;
}
