using Microsoft.AspNetCore.Mvc; using PlotLine.Services; namespace PlotLine.Controllers; public sealed class ExportsController(IExportService exports) : Controller { public async Task StoryBible(int projectId, string format = "html") => ExportResult(await exports.ExportStoryBibleAsync(projectId, format), format); public async Task NarrativeTimeline(int projectId, string format = "html") => ExportResult(await exports.ExportNarrativeTimelineAsync(projectId, format), format); public async Task Character(int id, string format = "html") => ExportResult(await exports.ExportCharacterReferenceAsync(id, format), format); public async Task SceneBrief(int id, string format = "html") => ExportResult(await exports.ExportSceneBriefAsync(id, format), format); public async Task ChapterBrief(int id, string format = "html") => ExportResult(await exports.ExportChapterBriefAsync(id, format), format); public async Task WritingSession(int sceneId, string format = "html") => ExportResult(await exports.ExportWriterSessionBriefAsync(sceneId, format), format); public async Task ResearchPack(int projectId, string format = "html") => ExportResult(await exports.ExportResearchPackAsync(projectId, format), format); public async Task Search(int projectId, string q, string format = "html") => ExportResult(await exports.ExportSearchResultsAsync(projectId, q, format), format); private IActionResult ExportResult((string FileName, string ContentType, string Content) export, string format) { if (string.Equals(format, "html", StringComparison.OrdinalIgnoreCase)) { return Content(export.Content, export.ContentType); } return File(System.Text.Encoding.UTF8.GetBytes(export.Content), export.ContentType, export.FileName); } }