using IWS5.Importer.Abstractions.FileSystem;
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;
using Syncfusion.Pdf;
using IWS5.Importer.Abstractions.Enums;

namespace IWS5.Importer.Worker.Conversion;

public class PowerPointFileConverter : IFileConverter
{
    private static readonly HashSet<string> Extensions = new(StringComparer.OrdinalIgnoreCase)
    {
        SupportedExtension.Pptx.ToString().ToLowerInvariant()
    };

    public bool CanConvert(string extension) => Extensions.Contains(extension);

    public async Task ConvertAsync(string inputPath, string outputPath, CancellationToken cancellationToken)
    {
        using FileStream fileStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read);
        using IPresentation presentation = Presentation.Open(fileStream);
        using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation);
        using FileStream pdfStream = new FileStream(outputPath, FileMode.Create, FileAccess.ReadWrite);

        pdfDocument.Save(pdfStream);

        await Task.CompletedTask;
    }
}
