using System.Data; using System.Text.Json; using Dapper; using PlotLine.Services.NativeCompanion; namespace PlotLine.Data; public sealed class NativeImportedChapter {public string ChapterKey{get;set;}="";public string ContentHash{get;set;}="";public int ReviewVersion{get;set;}} public interface INativeImportRepository { Task> List(int user,int book); Task Result(int user,Guid operation); Task Commit(int user,Guid operation,NativeImportPlan plan); } public sealed class NativeImportRepository(ISqlConnectionFactory factory):INativeImportRepository { public async Task> List(int user,int book){using var db=factory.CreateConnection();return (await db.QueryAsync("dbo.NativeReviewImport",new{Action="List",UserID=user,BookID=book},commandType:CommandType.StoredProcedure)).ToArray();} public async Task Result(int user,Guid operation){using var db=factory.CreateConnection();return await db.QuerySingleOrDefaultAsync("dbo.NativeReviewImport",new{Action="Result",UserID=user,OperationID=operation},commandType:CommandType.StoredProcedure);} public async Task Commit(int user,Guid operation,NativeImportPlan plan) { using var db=factory.CreateConnection();using var sets=await db.QueryMultipleAsync("dbo.NativeReviewImport",new{Action="Commit",UserID=user,OperationID=operation,BookID=plan.BookID,DocumentGuid=plan.ManuscriptID,ItemsJson=JsonSerializer.Serialize(plan.Items)},commandType:CommandType.StoredProcedure,commandTimeout:120); // The canonical build emits its four established sets. Consume through the final // post-commit result so a later source-save failure cannot masquerade as success. await sets.ReadAsync();await sets.ReadAsync();await sets.ReadAsync();await sets.ReadAsync();return await sets.ReadSingleAsync(); } }