using System.Text.Json; using PlotLine.Models; using PlotLine.Services; namespace PlotLine.ViewModels; public sealed class StoryIntelligenceExceptionReviewViewModel { public Guid? BatchID { get; init; } public int BookID { get; init; } public int ProjectID { get; init; } public string CanonicalController => Module switch { "Knowledge" => "StoryBible", "Relationships" => "RelationshipMap", _ => "StoryAssets" }; public string Module { get; init; } = ""; public string Scope { get; init; } = "Attention"; public StoryIntelligenceReviewSummary Summary { get; init; } = new(); public int Page { get; init; } public int PageCount { get; init; } public IReadOnlyList Items { get; init; } = []; public IReadOnlyList History { get; init; } = []; } public sealed class StoryIntelligenceReviewEntry { public required StoryIntelligenceReviewCandidateRow Row { get; init; } public string Pair { get; init; } = ""; public string PairKey { get; init; } = ""; public string Direction { get; init; } = ""; public string Detail { get; init; } = ""; public IReadOnlyList Observations { get; init; } = []; public string Evidence { get; init; } = ""; public string State { get; init; } = ""; public bool Pending => Row.DecisionStatus == "Pending"; public StoryIntelligenceReviewAssessment Assessment => string.IsNullOrWhiteSpace(Row.AssessmentJson) ? new(StoryIntelligenceReviewAssessment.Unassessed, ["This import has not been assessed for review priority. Update priorities using the saved analysis."]) : JsonSerializer.Deserialize(Row.AssessmentJson, StoryIntelligenceExceptionReviewService.JsonOptions)!; public string Status => Row.DecisionStatus switch { "AutoAccepted" => "Automatically tracked", "Reviewed" => Row.DecisionAction == "Ignore" ? "Ignored by you" : "Reviewed by you", _ => Row.ReviewPriority switch { "Attention" => "Needs attention", "Optional" => "Worth reviewing", _ => "Not yet assessed" } }; public static StoryIntelligenceReviewEntry From(StoryIntelligenceReviewCandidateRow row) { var options = StoryIntelligenceExceptionReviewService.JsonOptions; if (row.Module == StoryIntelligenceReviewModules.Relationships) { var x = JsonSerializer.Deserialize(row.CandidatePayloadJson, options)!; var pair = new[] { x.CharacterAName, x.CharacterBName }.OrderBy(n => n, StringComparer.OrdinalIgnoreCase); return new() { Row = row, Pair = string.Join(" / ", pair), PairKey = x.CharacterAID > 0 && x.CharacterBID > 0 ? $"{Math.Min(x.CharacterAID, x.CharacterBID)}:{Math.Max(x.CharacterAID, x.CharacterBID)}" : string.Join(" / ", pair), Direction = $"{x.CharacterAName} {(x.IsReciprocal ? "↔" : "→")} {x.CharacterBName}", Detail = x.Development ?? x.ExampleContext ?? "", State = x.RelationshipState, Evidence = x.ExampleContext ?? "", Observations = x.Observations }; } if (row.Module == StoryIntelligenceReviewModules.Knowledge) { var x = JsonSerializer.Deserialize(row.CandidatePayloadJson, options)!; return new() { Row = row, Detail = $"{x.CharacterName} · {x.KnowledgeStateName}", State = x.KnowledgeStateName, Evidence = x.Evidence ?? "", Observations = x.Observations }; } var a = JsonSerializer.Deserialize(row.CandidatePayloadJson, options)!; return new() { Row = row, Detail = $"{a.Category} · {a.AppearsInScenes} scenes", Evidence = a.ExampleContext ?? "" }; } } public sealed class StoryIntelligenceExceptionTileViewModel { public Guid? BatchID { get; init; } public string Module { get; init; } = ""; public bool Blocked { get; init; } public StoryIntelligenceReviewSummary? Summary { get; init; } }