@model StoryIntelligenceDiagnosticsViewModel
@{
    ViewData["Title"] = "Story Intelligence Diagnostics";
}

<div class="page-heading compact">
    <div>
        <p class="eyebrow">Admin utility</p>
        <h1>Story Intelligence Diagnostics</h1>
        <p class="lead-text">Build and configuration checks only. This page does not make a live OpenAI request.</p>
    </div>
</div>

<nav class="mb-3" aria-label="Breadcrumb">
    <a asp-controller="Projects" asp-action="Index">Projects</a>
    <span class="muted"> / </span>
    <a asp-action="Index">Admin</a>
    <span class="muted"> / Story Intelligence Diagnostics</span>
</nav>

@if (!string.IsNullOrWhiteSpace(Model.ErrorMessage))
{
    <div class="alert alert-warning">@Model.ErrorMessage</div>
}

<section class="edit-panel">
    <h2>OpenAI configuration</h2>
    <div class="row g-3">
        <div class="col-md-4">
            <div class="border rounded p-3 h-100">
                <p class="eyebrow">Model</p>
                <h3 class="mb-0">@Model.Model</h3>
            </div>
        </div>
        <div class="col-md-4">
            <div class="border rounded p-3 h-100">
                <p class="eyebrow">API key</p>
                <h3 class="mb-0">@StatusText(Model.ApiKeyConfigured)</h3>
            </div>
        </div>
        <div class="col-md-4">
            <div class="border rounded p-3 h-100">
                <p class="eyebrow">Client</p>
                <h3 class="mb-0">@StatusText(Model.ClientConstructed)</h3>
            </div>
        </div>
    </div>
    <dl class="mt-3 mb-0">
        <dt>Max output tokens</dt>
        <dd>@Model.MaxOutputTokens.ToString("N0")</dd>
        <dt>Chapter Structure model</dt>
        <dd>@Model.ChapterStructureModel</dd>
        <dt>Scene Intelligence model</dt>
        <dd>@Model.SceneIntelligenceModel</dd>
        <dt>Timeout</dt>
        <dd>@Model.TimeoutSeconds seconds</dd>
        <dt>Live API status</dt>
        <dd>@Model.ConnectionStatus</dd>
    </dl>
</section>

<section class="edit-panel">
    <h2>Prompt repository</h2>
    <div class="row g-3">
        <div class="col-md-3">
            <div class="border rounded p-3 h-100">
                <p class="eyebrow">Repository</p>
                <h3 class="mb-0">@StatusText(Model.PromptRepositoryHealthy)</h3>
            </div>
        </div>
        <div class="col-md-3">
            <div class="border rounded p-3 h-100">
                <p class="eyebrow">Scene prompt</p>
                <h3 class="mb-0">@StatusText(Model.ScenePromptLoaded)</h3>
            </div>
        </div>
        <div class="col-md-3">
            <div class="border rounded p-3 h-100">
                <p class="eyebrow">Prompt version</p>
                <h3 class="mb-0">@Model.PromptVersion</h3>
            </div>
        </div>
        <div class="col-md-3">
            <div class="border rounded p-3 h-100">
                <p class="eyebrow">Substitution</p>
                <h3 class="mb-0">@StatusText(Model.RuntimeSubstitutionWorks)</h3>
            </div>
        </div>
    </div>
    <dl class="mt-3 mb-0">
        <dt>Prompt file</dt>
        <dd>@Model.PromptFileName</dd>
        <dt>Prompt length</dt>
        <dd>@Model.ScenePromptLength.ToString("N0") characters</dd>
    </dl>
</section>

<section class="edit-panel">
    <h2>Manual dry run</h2>
    <p>This admin-only tool performs live API verification by loading the prompt, substituting test scene data and making one OpenAI request with extraction-focused settings. It does not save data.</p>
    <a class="btn btn-primary" asp-action="StoryIntelligenceTest">Open dry run</a>
    <a class="btn btn-outline-primary" asp-action="ChapterStructureTest">Open chapter structure test</a>
    <a class="btn btn-outline-primary" asp-action="ChapterStoryIntelligenceTest">Open combined pipeline test</a>
</section>

@functions {
    private static string StatusText(bool value) => value ? "Configured" : "Missing";
}
