using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;

namespace NexusShell.Models;

public enum NexusPhotosSection
{
    Library,
    Favorites,
    Recent,
    Folders,
    Pictures,
    Screenshots,
    Downloads,
    Camera,
}

public enum NexusImageZoomMode
{
    Fit,
    Fill,
    ActualSize,
}

public sealed class NexusPhotoItem
{
    public required string FullPath { get; init; }
    public required string FileName { get; init; }
    public required string FolderPath { get; init; }
    public required string FolderLabel { get; init; }
    public long FileSizeBytes { get; init; }
    public DateTime CreatedUtc { get; init; }
    public DateTime ModifiedUtc { get; init; }
    public int Width { get; init; }
    public int Height { get; init; }
    public required string Format { get; init; }
    public required string Extension { get; init; }
    public bool IsFavorite { get; set; }
}

public sealed class NexusPhotoFolderSummary
{
    public required string FolderPath { get; init; }
    public required string Label { get; init; }
    public int PhotoCount { get; init; }
    public long TotalBytes { get; init; }
    public DateTime LatestModifiedUtc { get; init; }
    public string? CoverPhotoPath { get; init; }
}

public sealed class NexusPhotoMetadata
{
    public required string FileName { get; init; }
    public required string SizeLabel { get; init; }
    public required string CreatedLabel { get; init; }
    public required string ModifiedLabel { get; init; }
    public required string ResolutionLabel { get; init; }
    public required string Format { get; init; }
    public required string FolderLabel { get; init; }
    public required string FullPath { get; init; }
    public bool HasSelection { get; init; }
}

public sealed class NexusPhotoNavItem
{
    public required NexusPhotosSection Section { get; init; }
    public required string Label { get; init; }
    public required string IconPath { get; init; }
}

public sealed class NexusPhotoGridItem : INotifyPropertyChanged
{
    private ImageSource? _thumbnail;
    private bool _isSelected;

    public NexusPhotoGridItem(NexusPhotoItem photo) => Photo = photo;

    public NexusPhotoItem Photo { get; }

    public ImageSource? Thumbnail
    {
        get => _thumbnail;
        set
        {
            if (_thumbnail == value)
            {
                return;
            }

            _thumbnail = value;
            PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(nameof(Thumbnail)));
            PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(nameof(HasThumbnail)));
        }
    }

    public bool HasThumbnail => _thumbnail is not null;

    public bool IsSelected
    {
        get => _isSelected;
        set
        {
            if (_isSelected == value)
            {
                return;
            }

            _isSelected = value;
            PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(nameof(IsSelected)));
        }
    }

    public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;
}

public sealed class NexusPhotoHomeSection
{
    public required string Title { get; init; }
    public required string IconPath { get; init; }
    public required IReadOnlyList<NexusPhotoGridItem> Items { get; init; }
}
