using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using PlotLine.Services; using PlotLine.ViewModels; namespace PlotLine.Controllers; [Authorize(Policy = "AdminOnly")] [Route("Development")] public sealed class DevelopmentController( IWebHostEnvironment environment, ICurrentUserService currentUser, IIllustrationLibraryService illustrationLibrary, IStoryIntelligenceVisualisationSnapshotService snapshots) : Controller { [HttpGet("StoryIntelligenceExperience")] public async Task StoryIntelligenceExperience([FromQuery] string? mode, [FromQuery] int? runId) { if (!environment.IsDevelopment()) { return NotFound(); } if (!string.Equals(mode, "simulation", StringComparison.OrdinalIgnoreCase) && runId.HasValue && currentUser.UserId is int userId) { var realModel = await snapshots.BuildSnapshotAsync(runId.Value, userId); if (realModel is null) { return NotFound(); } return View(realModel); } var model = StoryIntelligenceExperiencePrototypeData.Build(); await illustrationLibrary.ApplyApprovedIllustrationsAsync(model); if (!string.Equals(mode, "simulation", StringComparison.OrdinalIgnoreCase) && currentUser.UserId is int selectorUserId) { model = new StoryIntelligenceExperiencePrototypeViewModel { Mode = "selector", AvailableRuns = await snapshots.ListRunOptionsAsync(selectorUserId), ProjectName = model.ProjectName, BookTitle = model.BookTitle, Scenes = model.Scenes, SnapshotMessage = "Choose a persisted Story Intelligence run, or open simulation mode." }; } return View(model); } }