using ImageConvertService.Biz.Models;

namespace ImageConvertService.Biz;

public class ArchiveEntrySkipper
{
    public (List<ArchiveEntry> Direct, List<ArchiveEntry> Convert) Filter(IReadOnlyCollection<ArchiveEntry> items, string? skipPsv)
    {
        List<ArchiveEntry> d = new(), c = new();

        if (string.IsNullOrWhiteSpace(skipPsv))
        {
            c.AddRange(items);
            return (d, c);
        }

        var skipSuffix = skipPsv.Split("|").Distinct().ToArray();
        foreach (var entry in items)
        {
            if (skipSuffix.Any(p => entry.PathAndName.EndsWith(p, StringComparison.OrdinalIgnoreCase)))
                d.Add(entry);
            else
                c.Add(entry);
        }

        return (d, c);
    }
}