using CommunityToolkit.Mvvm.ComponentModel;
using MarcusLaw.OutlookAddin.Core.Configuration;
using MarcusLaw.OutlookAddin.Core.Models;

namespace MarcusLaw.OutlookAddin.UI.ViewModels
{
    /// <summary>
    /// One row in the Folders tab of the Settings dialog. Wraps a
    /// <see cref="FolderTreeNode"/> with three observable fields the user
    /// can toggle: IsWatched, Mode, ConfidenceThreshold.
    /// </summary>
    public sealed partial class FolderRowViewModel : ObservableObject
    {
        public FolderTreeNode Node { get; }

        [ObservableProperty]
        private bool isWatched;

        [ObservableProperty]
        private WatchMode mode = WatchMode.NotifyOnly;

        [ObservableProperty]
        private double confidenceThreshold = 0.8;

        public string DisplayLabel => new string(' ', Node.Depth * 2) + Node.DisplayName;

        public string FullPath => Node.StoreDisplayName + Node.FolderPath;

        public FolderRowViewModel(FolderTreeNode node)
        {
            Node = node;
        }

        public WatchedFolder ToWatchedFolder() => new WatchedFolder
        {
            StoreId = Node.StoreId,
            FolderPath = Node.FolderPath,
            Mode = Mode,
            ConfidenceThreshold = ConfidenceThreshold
        };
    }
}
