using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using PlotLine.Models;
using PlotLine.Services;
using System.Diagnostics;

namespace PlotLine.Controllers
{
    [AllowAnonymous]
    public class HomeController(IConfiguration configuration) : Controller
    {
        [HttpGet("/", Name = PublicRouteNames.Home)]
        public IActionResult Index()
        {
            const string description = "PlotDirector helps authors organise characters, plot threads, timelines, story assets, relationships, and continuity so they can finish complex novels with confidence.";
            PublicSeo.Apply(ViewData, configuration, new SeoMetadata
            {
                Title = "Novel Planning Software for Authors",
                Description = description,
                Keywords = "novel planning software, writing software, story planning app, author tools, plot tracking, character tracking, story timeline, novel organisation, fiction writing software, series writing software, continuity tracking, plot threads, story bible",
                CanonicalPath = "/",
                JsonLd =
                [
                    PublicSeo.JsonLd(new Dictionary<string, object?>
                    {
                        ["@context"] = "https://schema.org",
                        ["@type"] = "WebSite",
                        ["name"] = "PlotDirector",
                        ["url"] = PublicSeo.BaseUrl(configuration),
                        ["description"] = "Novel planning and story organisation software for authors."
                    }),
                    PublicSeo.JsonLd(new Dictionary<string, object?>
                    {
                        ["@context"] = "https://schema.org",
                        ["@type"] = "SoftwareApplication",
                        ["name"] = "PlotDirector",
                        ["applicationCategory"] = "WritingApplication",
                        ["operatingSystem"] = "Web",
                        ["url"] = PublicSeo.BaseUrl(configuration),
                        ["description"] = description
                    }),
                    PublicSeo.WebPageJsonLd(configuration, "WebPage", "PlotDirector", "/", description)
                ]
            });
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
