namespace Health.Infrastructure.AI;

public sealed class ChatCompletionRequest
{
    public string Model { get; set; } = string.Empty;
    public List<ChatMessage> Messages { get; set; } = [];
    public bool Stream { get; set; }
    public int MaxTokens { get; set; } = 2048;
    public float Temperature { get; set; } = 0.7f;
    public float? TopP { get; set; }
    public List<ToolDefinition>? Tools { get; set; }
    public string? ToolChoice { get; set; }

    [System.Text.Json.Serialization.JsonPropertyName("vl_high_resolution_images")]
    public bool VlHighResolutionImages { get; set; }
}

public sealed class ChatMessage
{
    public string Role { get; set; } = string.Empty;
    public object? Content { get; set; } = string.Empty;

    [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
    public string? ToolCallId { get; set; }

    [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
    public List<ToolCall>? ToolCalls { get; set; }
}

public sealed class ToolDefinition
{
    public string Type { get; set; } = "function";
    public ToolFunction Function { get; set; } = new();
}

public sealed class ToolFunction
{
    public string Name { get; set; } = string.Empty;
    public string Description { get; set; } = string.Empty;
    public object Parameters { get; set; } = new();
}

public sealed class ToolCall
{
    public string Id { get; set; } = string.Empty;
    public string Type { get; set; } = "function";
    public ToolCallFunction Function { get; set; } = new();
}

public sealed class ToolCallFunction
{
    public string Name { get; set; } = string.Empty;
    public string Arguments { get; set; } = string.Empty;
}

public sealed class ChatCompletionResponse
{
    public string Id { get; set; } = string.Empty;
    public List<Choice> Choices { get; set; } = [];
}

public sealed class Choice
{
    public int Index { get; set; }
    public ResponseMessage? Message { get; set; }
    public ResponseDelta? Delta { get; set; }
    public string? FinishReason { get; set; }
}

public sealed class ResponseMessage
{
    public string Role { get; set; } = string.Empty;
    public string? Content { get; set; }
    public List<ToolCall>? ToolCalls { get; set; }
}

public sealed class ResponseDelta
{
    public string? Content { get; set; }
    public string? Role { get; set; }
}
