using System.Text.Json; using PlotLine.Models; namespace PlotLine.Services.Manuscript; // Versioned provider contract; normalized decimals remain only at the legacy domain boundary. public static class ChapterStructureIntegerContract { public static StoryIntelligenceResponseContract ForParagraphCount(int count) { if(count<1)throw new ArgumentOutOfRangeException(nameof(count)); var schema=System.Text.Json.Nodes.JsonNode.Parse(JsonSerializer.Serialize(Contract.Schema))!; var boundaries=schema["properties"]!["sceneBoundaries"]!;boundaries["minItems"]=1;boundaries["maxItems"]=count; foreach(var name in new[]{"sceneNumber","startParagraph","endParagraph"})boundaries["items"]!["properties"]![name]!["maximum"]=count; return new(){Name=Contract.Name,Schema=schema,Strict=true}; } public static StoryIntelligenceResponseContract Contract {get;}=new(){Name="chapter_structure_v2",Schema=JsonSerializer.Deserialize(""" {"type":"object","additionalProperties":false,"required":["schemaVersion","chapterSummary","defaultPov","mixedPov","sceneBoundaries"],"properties":{ "schemaVersion":{"type":"string","enum":["2.0"]},"chapterSummary":{"type":"string"},"defaultPov":{"$ref":"#/$defs/pov"},"mixedPov":{"type":"boolean"}, "sceneBoundaries":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["sceneNumber","startParagraph","endParagraph","suggestedTitle","structuralSummary","structuralSetting","povOverride","confidence","reason"],"properties":{ "sceneNumber":{"type":"integer","minimum":1},"startParagraph":{"type":"integer","minimum":1},"endParagraph":{"type":"integer","minimum":1}, "suggestedTitle":{"type":"string"},"structuralSummary":{"type":"string"},"structuralSetting":{"type":["string","null"]},"povOverride":{"$ref":"#/$defs/pov"},"confidence":{"type":"integer","minimum":0,"maximum":100},"reason":{"type":"string"}}}}}, "$defs":{"pov":{"anyOf":[{"type":"null"},{"type":"object","additionalProperties":false,"required":["characterName","confidence","evidence","isExplicit"],"properties":{"characterName":{"type":"string"},"confidence":{"type":"integer","minimum":0,"maximum":100},"evidence":{"type":"string"},"isExplicit":{"type":"boolean"}}}]}}} """)}; }