using System.Linq;
using ClaudeDo.Ui.Services;

namespace ClaudeDo.Ui.ViewModels.Islands;

/// Pure mapping from a merge-preview DTO to display text + color flags.
public static class MergePreviewPresenter
{
    public static (string Text, bool IsClean, bool IsConflict) Describe(MergePreviewDto? dto)
    {
        if (dto is null) return ("", false, false);

        switch (dto.Status)
        {
            case "clean":
                var unit = dto.ChangedFileCount == 1 ? "file" : "files";
                return ($"Merges cleanly · {dto.ChangedFileCount} {unit}", true, false);

            case "conflict":
                var names = string.Join(", ", dto.ConflictFiles.Take(3));
                var more = dto.ConflictFiles.Count > 3 ? $" (+{dto.ConflictFiles.Count - 3} more)" : "";
                return ($"Conflicts in {names}{more}", false, true);

            default:
                return ("Mergeability unknown", false, false);
        }
    }
}
