using RazorLight;
using Documents.Interfaces;

namespace Documents.Services
{
    public class RazorTemplateEngine : ITemplateRenderer
    {
        private readonly RazorLightEngine _engine;

        public RazorTemplateEngine()
        {
            var templatesPath = Path.Combine(AppContext.BaseDirectory, "Templates");
            _engine = new RazorLightEngineBuilder()
                .UseFileSystemProject(templatesPath)
                .UseMemoryCachingProvider()
                .Build();
        }

        public async Task<string> RenderAsync<TModel>(string templateKey, TModel model)
        {
            return await _engine.CompileRenderAsync(templateKey, model);
        }
    }
}
