using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace NexusShell.Models;

public enum NexusDefaultAppId
{
    Photos,
    Media,
    FilesPreview,
    Browser,
}

public sealed class NexusDefaultAppsConfig
{
    public int Version { get; set; } = 1;

    public Dictionary<string, string> CategoryHandlers { get; set; } = new(StringComparer.OrdinalIgnoreCase);

    public Dictionary<string, string> ExtensionOverrides { get; set; } = new(StringComparer.OrdinalIgnoreCase);
}

public sealed class NexusDefaultAppCategory
{
    public required string Id { get; init; }
    public required string Label { get; init; }
    public required string ExtensionsLabel { get; init; }
    public required IReadOnlyList<string> Extensions { get; init; }
    public NexusDefaultAppId DefaultApp { get; init; }
}

public sealed class NexusDefaultAppOption
{
    public required NexusDefaultAppId AppId { get; init; }
    public required string Label { get; init; }
    public required string Description { get; init; }
}

public sealed class NexusDefaultAppPreferenceRow : INotifyPropertyChanged
{
    private NexusDefaultAppId _selectedApp;

    public required string CategoryId { get; init; }
    public required string CategoryLabel { get; init; }
    public required string ExtensionsLabel { get; init; }

    public NexusDefaultAppId SelectedApp
    {
        get => _selectedApp;
        set
        {
            if (_selectedApp == value)
            {
                return;
            }

            _selectedApp = value;
            OnPropertyChanged();
        }
    }

    public event PropertyChangedEventHandler? PropertyChanged;

    private void OnPropertyChanged([CallerMemberName] string? name = null) =>
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}

public sealed class NexusOpenWithChoice
{
    public required NexusDefaultAppId AppId { get; init; }
    public required string Label { get; init; }
    public required string Description { get; init; }
    public required string IconPath { get; init; }
}
