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

namespace Hua.Todo.Avalonia.ViewModels;

/// <summary>
/// 应用托盘交互的 ViewModel。
/// 用于为 <see cref="global::Avalonia.Controls.TrayIcon"/> 提供命令与提示文本，并将托盘事件路由到应用层逻辑。
/// </summary>
public sealed partial class AppTrayViewModel : ObservableObject
{
    private readonly Action _showMainWindow;
    private readonly Action _exitApplication;

    /// <summary>
    /// 创建 <see cref="AppTrayViewModel"/>。
    /// </summary>
    /// <param name="trayTooltipText">托盘提示文本（部分平台有长度限制）。</param>
    /// <param name="showMainWindow">显示/激活主窗口回调。</param>
    /// <param name="exitApplication">退出应用回调（应触发应用生命周期关闭）。</param>
    public AppTrayViewModel(string trayTooltipText, Action showMainWindow, Action exitApplication)
    {
        TrayTooltipText = trayTooltipText;
        _showMainWindow = showMainWindow;
        _exitApplication = exitApplication;

        ShowMainWindowCommand = new RelayCommand(_showMainWindow);
        ExitApplicationCommand = new RelayCommand(_exitApplication);
    }

    /// <summary>
    /// 托盘提示文本。
    /// </summary>
    public string TrayTooltipText { get; }

    /// <summary>
    /// 显示/激活主窗口命令。
    /// </summary>
    public IRelayCommand ShowMainWindowCommand { get; }

    /// <summary>
    /// 退出应用命令。
    /// </summary>
    public IRelayCommand ExitApplicationCommand { get; }
}

