using System.Collections.Generic;

namespace PolyTrader.Modules.Supervisor.Agent
{
    /// <summary>Chat-Nachricht im OpenAI-/OpenRouter-Schema (Rollen: system/user/assistant/tool).</summary>
    public sealed class ChatMessage
    {
        public string Role { get; init; } = "user";
        public string? Content { get; init; }

        /// <summary>Vom Modell angeforderte Tool-Aufrufe (nur Rolle assistant).</summary>
        public List<ToolCall>? ToolCalls { get; init; }

        /// <summary>Bezug auf den beantworteten Tool-Aufruf (nur Rolle tool).</summary>
        public string? ToolCallId { get; init; }

        public static ChatMessage System(string content) => new() { Role = "system", Content = content };
        public static ChatMessage User(string content) => new() { Role = "user", Content = content };
        public static ChatMessage Assistant(string? content, List<ToolCall>? toolCalls = null) =>
            new() { Role = "assistant", Content = content, ToolCalls = toolCalls };
        public static ChatMessage ToolResult(string toolCallId, string content) =>
            new() { Role = "tool", ToolCallId = toolCallId, Content = content };
    }

    /// <summary>Ein Tool-Aufruf des Modells (Function-Calling).</summary>
    public sealed record ToolCall(string Id, string Name, string ArgumentsJson);

    /// <summary>Antwort des Modells: Text ODER Tool-Aufrufe (oder beides).</summary>
    public sealed class ChatResponse
    {
        public string? Content { get; init; }
        public List<ToolCall> ToolCalls { get; init; } = new();
        public int PromptTokens { get; init; }
        public int CompletionTokens { get; init; }
    }
}
