using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using PlotLine.Services;

namespace PlotLine.Controllers;

[Authorize]
public sealed class DynamicsController(IDynamicsService dynamics) : Controller
{
    public async Task<IActionResult> Story(int projectId)
    {
        var model = await dynamics.GetStoryDynamicsAsync(projectId);
        return model is null ? NotFound() : View(model);
    }

    public async Task<IActionResult> Character(int id)
    {
        var model = await dynamics.GetCharacterArcAsync(id);
        return model is null ? NotFound() : View(model);
    }

    public async Task<IActionResult> Relationship(int id)
    {
        var model = await dynamics.GetRelationshipEvolutionAsync(id);
        return model is null ? NotFound() : View(model);
    }

    public async Task<IActionResult> Knowledge(int id)
    {
        var model = await dynamics.GetKnowledgeTimelineAsync(id);
        return model is null ? NotFound() : View(model);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> RunChecks(int projectId, int? bookId, int? sceneId)
    {
        await dynamics.RunContinuityChecksAsync(projectId, bookId, sceneId);
        return RedirectToAction(nameof(Story), new { projectId });
    }
}
