using ClaudeDo.Data.Filtering.Filters;

namespace ClaudeDo.Data.Filtering;

/// <summary>
/// Resolves a list id (e.g. "virtual:queued", "user:abc") to the filter that
/// owns its semantics. Smart and virtual filters are singletons; user-list
/// filters are constructed on demand from the id.
/// </summary>
public sealed class TaskListFilterRegistry
{
    public const string UserListPrefix = "user:";

    private static readonly IReadOnlyDictionary<string, ITaskListFilter> BuiltIn =
        new Dictionary<string, ITaskListFilter>(StringComparer.Ordinal)
        {
            ["smart:my-day"]    = new MyDayFilter(),
            ["smart:important"] = new ImportantFilter(),
            ["smart:planned"]   = new PlannedFilter(),
            ["virtual:queued"]  = new QueuedFilter(),
            ["virtual:running"] = new RunningFilter(),
            ["virtual:review"]  = new ReviewFilter(),
        };

    /// <summary>
    /// Resolve a filter for a list id, or null if the id is unknown.
    /// </summary>
    public ITaskListFilter? Resolve(string listId)
    {
        if (BuiltIn.TryGetValue(listId, out var f)) return f;
        if (listId.StartsWith(UserListPrefix, StringComparison.Ordinal))
        {
            var inner = listId[UserListPrefix.Length..];
            return string.IsNullOrEmpty(inner) ? null : new UserListFilter(inner);
        }
        return null;
    }
}
