using RazorLight;
using Documents.Interfaces;

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

        public RazorLightTemplateRenderer()
        {
            _engine = new RazorLightEngineBuilder()
                .UseEmbeddedResourcesProject(typeof(RazorLightTemplateRenderer))
                .UseMemoryCachingProvider()
                .Build();
        }

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