using Microsoft.Extensions.Logging;
using Microsoft.Toolkit.Uwp.Notifications;

namespace PSLauncher.App.Services;

public sealed class ToastService : IToastService
{
    private readonly ILogger<ToastService> _logger;

    public ToastService(ILogger<ToastService> logger) => _logger = logger;

    public void ShowSuccess(string title, string message) => Show(title, message, "PROSERVE");
    public void ShowError(string title, string message)   => Show(title, message, "PROSERVE");
    public void ShowInfo(string title, string message)    => Show(title, message, "PROSERVE");

    private void Show(string title, string message, string attribution)
    {
        try
        {
            new ToastContentBuilder()
                .AddText(title)
                .AddText(message)
                .AddAttributionText(attribution)
                .Show();
        }
        catch (Exception ex)
        {
            // Si Action Center n'est pas dispo (ancien Windows, COM bloqué…), on log mais on ne plante pas
            _logger.LogWarning(ex, "Failed to show Windows toast");
        }
    }
}
