using Core;
using Core.Actions;
using Core.Helpers;
using Core.Templates;
using Core.Yaml;
using Generator.Infrastructure.TemplateFiller;
namespace Generator.Infrastructure.Export;
///
/// Provides multiple methods to specification references
///
public class Exporter
{
private readonly ITemplateFactory _templateFactory;
public Exporter(ITemplateFactory factory)
{
_templateFactory = factory;
}
///
/// Export file references as plant uml diagram
///
/// plantuml data needed for exportation
/// File to export
public void PlantUml(PlantUmlExport export, ISpecFile file)
{
var yaml = TypeHelper.SafeCast(file);
var input = export.LocalRoot.ConcatenateWith(export.Template);
var output = export.LocalRoot.ConcatenateWith(export.Output);
var references = new List<(string Package, string Reference)>();
var schemas = yaml.ReferencedSchemas.ToList();
for (var i = -1; i < schemas.Count; i++)
{
var baseFile = i == -1 ? yaml : schemas[i];
if(!baseFile.Location.IsInSameFolder(yaml.Location)) continue;
foreach (var reference in baseFile.ReferencedSchemas)
{
references.Add((baseFile.NugetPackage, reference.NugetPackage));
}
}
var data = new Dictionary()
{
{"specName", file.Folder},
{"packages", references.Select(t => t.Package).ToHashSet()},
{"references", references}
};
var template = _templateFactory.GetTemplate(input.ToString(), data);
var f = new MustacheFiller(template);
f.Fill();
f.Write(output.ToString());
}
}