using Codex.Dal.Enums;

namespace Codex.Dal.Entities;

/// <summary>
/// Represents an AI agent with its configuration and model settings.
/// </summary>
public class Agent
{
    /// <summary>
    /// Unique identifier for the agent
    /// </summary>
    public Guid Id { get; set; }

    /// <summary>
    /// Display name of the agent
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    /// Description of the agent's purpose and capabilities
    /// </summary>
    public string Description { get; set; } = string.Empty;

    /// <summary>
    /// Type of agent (CodeGenerator, CodeReviewer, etc.)
    /// </summary>
    public AgentType Type { get; set; }

    /// <summary>
    /// Model provider name (e.g., "openai", "anthropic", "ollama")
    /// </summary>
    public string ModelProvider { get; set; } = string.Empty;

    /// <summary>
    /// Specific model name (e.g., "gpt-4o", "claude-3.5-sonnet", "codellama:7b")
    /// </summary>
    public string ModelName { get; set; } = string.Empty;

    /// <summary>
    /// Type of provider (CloudApi, LocalEndpoint, Custom)
    /// </summary>
    public ModelProviderType ProviderType { get; set; }

    /// <summary>
    /// Model endpoint URL (e.g., "http://localhost:11434" for Ollama). Nullable for cloud APIs.
    /// </summary>
    public string? ModelEndpoint { get; set; }

    /// <summary>
    /// Encrypted API key for cloud providers. Null for local endpoints.
    /// </summary>
    public string? ApiKeyEncrypted { get; set; }

    /// <summary>
    /// Temperature parameter for model generation (0.0 to 2.0)
    /// </summary>
    public double Temperature { get; set; } = 0.7;

    /// <summary>
    /// Maximum tokens to generate in response
    /// </summary>
    public int MaxTokens { get; set; } = 4000;

    /// <summary>
    /// System prompt defining agent behavior and instructions
    /// </summary>
    public string SystemPrompt { get; set; } = string.Empty;

    /// <summary>
    /// Whether conversation memory is enabled for this agent
    /// </summary>
    public bool EnableMemory { get; set; } = true;

    /// <summary>
    /// Number of recent user/assistant/tool messages to include in context (system messages always included)
    /// </summary>
    public int ConversationWindowSize { get; set; } = 10;

    /// <summary>
    /// Current status of the agent
    /// </summary>
    public AgentStatus Status { get; set; } = AgentStatus.Active;

    /// <summary>
    /// When the agent was created
    /// </summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// When the agent was last updated
    /// </summary>
    public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// Soft delete flag
    /// </summary>
    public bool IsDeleted { get; set; } = false;

    // Navigation properties
    /// <summary>
    /// Tools available to this agent
    /// </summary>
    public ICollection<AgentTool> Tools { get; set; } = new List<AgentTool>();

    /// <summary>
    /// Execution history for this agent
    /// </summary>
    public ICollection<AgentExecution> Executions { get; set; } = new List<AgentExecution>();
}
