using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace ClawdDotNet.Desktop.ViewModels;

public sealed record AddAgentResultData(
    string AgentId,
    string DisplayName,
    string Model,
    string Description
);

public sealed partial class AddAgentViewModel : ViewModelBase
{
    [ObservableProperty]
    private string _agentId = "";

    [ObservableProperty]
    private string _displayName = "";

    [ObservableProperty]
    private string _selectedModel = "anthropic/claude-3-5-sonnet";

    [ObservableProperty]
    private string _description = "";

    [ObservableProperty]
    private string _statusMessage = "";

    public List<string> AvailableModels { get; } =
    [
        "anthropic/claude-3-5-sonnet",
        "anthropic/claude-3-opus",
        "openai/gpt-4o",
        "openai/gpt-4o-mini",
        "google/gemini-2.5-flash",
        "google/gemini-2.5-pro",
        "deepseek/deepseek-r1"
    ];

    public AddAgentResultData? Result { get; private set; }

    public event Action? CloseRequested;

    [RelayCommand]
    private void Confirm()
    {
        if (string.IsNullOrWhiteSpace(AgentId))
        {
            StatusMessage = "Bitte eine Agenten-ID eingeben.";
            return;
        }

        if (string.IsNullOrWhiteSpace(DisplayName))
        {
            StatusMessage = "Bitte einen Anzeigenamen eingeben.";
            return;
        }

        Result = new AddAgentResultData(
            AgentId.Trim(),
            DisplayName.Trim(),
            SelectedModel,
            Description.Trim()
        );

        CloseRequested?.Invoke();
    }

    [RelayCommand]
    private void Cancel()
    {
        Result = null;
        CloseRequested?.Invoke();
    }
}
