using SolutionErp.Application.Forms.Services;

namespace SolutionErp.Infrastructure.Forms;

public class FormRenderer : IFormRenderer
{
    private readonly DocxRenderer _docx = new();
    private readonly XlsxRenderer _xlsx = new();

    public Task<RenderResult> RenderAsync(
        string templateAbsolutePath,
        string format,
        IReadOnlyDictionary<string, string?> data,
        string outputFileName,
        CancellationToken ct = default)
    {
        return format.ToLowerInvariant() switch
        {
            "docx" => _docx.RenderAsync(templateAbsolutePath, data, outputFileName, ct),
            "xlsx" => _xlsx.RenderAsync(templateAbsolutePath, data, outputFileName, ct),
            _ => throw new NotSupportedException($"Format '{format}' không được hỗ trợ. Chỉ 'docx' hoặc 'xlsx'."),
        };
    }
}
