using IWS5.Server.Enums;

namespace IWS5.Server.Utils.Converter.TiffConverter;

internal class PdfFileToTiffConverter : IFileConverter
{
    private static readonly HashSet<string> Extensions = new(StringComparer.OrdinalIgnoreCase)
    {
        nameof(ConvertibleFileTypes.pdf).ToLowerInvariant()
    };

    public bool CanConvert(string sourceFileExtension, string targetFileExtension) => Extensions.Contains(sourceFileExtension) && 
        string.Equals(targetFileExtension, nameof(ConvertibleFileTypes.tiff), StringComparison.OrdinalIgnoreCase);

    public async Task<byte[]> ConvertAsync(byte[] inputFile)
    {
        try
        {
            return await PdfToTiffConverter.ConvertAsync(inputFile);
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException($"Error converting PDF to TIFF: {ex.Message}", ex);
        }
    }
}