using System;
using System.Collections.Generic;

namespace AIRuntime.Runtime.Providers.Ollama
{
    // =====================================================
    // REQUEST
    // =====================================================

    [Serializable]
    public class ChatRequest
    {
        public string model;
        public List<MessageDto> messages = new();
        public List<ToolDto> tools = new();
        public bool stream = false;
    }

    [Serializable]
    public class MessageDto
    {
        public string role;
        public string content;
        public List<string> images;

        // Used for tool result messages
        public string tool_call_id;
        public string name;

        // Used for assistant tool calls
        public List<ToolCallDto> tool_calls;
    }

    // =====================================================
    // TOOLS
    // =====================================================

    [Serializable]
    public class ToolDto
    {
        public string type = "function";

        public FunctionDto function = new();
    }

    [Serializable]
    public class FunctionDto
    {
        public string name;
        public string description;

        // JSON Schema object
        public object parameters;
    }

    // =====================================================
    // TOOL CALLS
    // =====================================================

    [Serializable]
    public class ToolCallDto
    {
        public string id;

        // Present in OpenAI-compatible responses
        public int index;

        public string type;

        public FunctionCallDto function;
    }

    [Serializable]
    public class FunctionCallDto
    {
        public string name;

        // JSON string returned by the model
        public string arguments;
    }

    // =====================================================
    // RESPONSE
    // =====================================================

    [Serializable]
    public class ChatResponse
    {
        public string id;
        public string @object;
        public long created;
        public string model;
        public string system_fingerprint;

        public List<ChoiceDto> choices = new();

        public UsageDto usage;
    }

    [Serializable]
    public class ChoiceDto
    {
        public int index;

        public MessageDto message;

        public string finish_reason;
    }

    [Serializable]
    public class UsageDto
    {
        public int prompt_tokens;
        public int completion_tokens;
        public int total_tokens;
    }
}
