namespace IWS5.Server.Utils.Merger;

public static class MergeFactory
{
    private static readonly Dictionary<Type, Lazy<IFileMerger>> LazyMergers = new()
    {
        { typeof(PdfMerger), new Lazy<IFileMerger>(() => new PdfMerger()) },
        { typeof(TiffMerger), new Lazy<IFileMerger>(() => new TiffMerger()) }
    };
    
    public static IFileMerger CreateMerger(string fileExtension)
    {
        foreach (var lazyConverter in LazyMergers.Values)
        {
            var converter = lazyConverter.Value;
            if (converter.CanMerge(fileExtension))
            {
                return converter;
            }
        }
        
        return null;
    }
}