using System.Text.Json; using PlotLine.Data; using PlotLine.Models.WritingSolver; namespace PlotLine.Services; // Authored presentation only; never changes graph choices, order fields or engine inputs. public sealed class WritingSolverPayoff { public sealed record Result(string Solution,string Family,string Action); public sealed record Unknown(string Node,string Choice); public sealed record Catalog(List Results,List Uncertainty); public Catalog Content { get; } private readonly HashSet<(string,string)> unknown; public WritingSolverPayoff(string path) { Content=JsonSerializer.Deserialize(File.ReadAllText(path),WritingSolverRepository.JsonOptions)??throw new InvalidDataException("Missing payoff catalogue."); if(Content.Results.Count!=52||Content.Results.Select(r=>r.Solution).Distinct().Count()!=52||Content.Results.Any(r=>!new[]{"plot-map","chronology","progression","people","trace","overview","workflow"}.Contains(r.Family)||string.IsNullOrWhiteSpace(r.Action)))throw new InvalidDataException("Invalid payoff mappings."); unknown=Content.Uncertainty.Select(x=>(x.Node,x.Choice)).ToHashSet(); } public Result For(string id)=>Content.Results.Single(r=>r.Solution==id); public bool IsUncertain(SolverNode node,SolverChoice choice)=>unknown.Contains((node.Id,choice.Id)); public IEnumerable OrderedChoices(SolverNode node)=>node.Choices.Where(c=>c.Active).OrderBy(c=>IsUncertain(node,c)).ThenBy(c=>c.Order); }