23 lines
1.4 KiB
C#
23 lines
1.4 KiB
C#
using System.Text.Json;
|
|
using PlotLine.Data;
|
|
using PlotLine.Models.WritingSolver;
|
|
namespace PlotLine.Services;
|
|
|
|
// Permanent editorial content only. Never supplies solver weights, choices or routes.
|
|
public sealed class WritingProblemEditorial
|
|
{
|
|
public WritingProblemCatalog Catalog { get; }
|
|
public WritingProblemEditorial(string path)
|
|
{
|
|
Catalog=JsonSerializer.Deserialize<WritingProblemCatalog>(File.ReadAllText(path),WritingSolverRepository.JsonOptions)??throw new InvalidDataException("Empty writing problem editorial catalogue.");
|
|
if(Catalog.Version!=1 || Catalog.Pages.Select(p=>p.Solution).Distinct().Count()!=Catalog.Pages.Count
|
|
|| Catalog.Areas.Select(a=>a.Id).Distinct().Count()!=Catalog.Areas.Count)throw new InvalidDataException("Invalid editorial catalogue identity.");
|
|
foreach(var page in Catalog.Pages)
|
|
if(!Catalog.Areas.Any(a=>a.Id==page.Area) || new[]{page.Title,page.Description,page.Recognition,page.Cause,page.Model,page.Distinction}.Any(string.IsNullOrWhiteSpace)
|
|
|| page.Inspect.Count<3 || page.SearchIntents.Count is <5 or >10
|
|
|| page.Related.Count>3 || page.Related.Any(id=>id==page.Solution || !Catalog.Pages.Any(p=>p.Solution==id)))
|
|
throw new InvalidDataException("Incomplete writing problem article.");
|
|
}
|
|
public WritingProblemArticle? Find(string solution)=>Catalog.Pages.FirstOrDefault(p=>p.Solution==solution);
|
|
}
|