namespace AIStudio.Assistants.BeyondFactsLab; /// /// A result of a preparation, such as the position paper, stored in the folder "results" of the preparation. /// /// /// The lab writes a draft, which the person reads, edits, and confirms; only a confirmed result can be exported. Like /// a work state, a result keeps its confirmed version while the person works on a new draft. Whether it is outdated /// is computed from the work states it was built from, see BflStaleness.IsOutdated. /// public sealed class BflResult { /// /// The version of the stored form this version of AI Studio writes. Raise it with every new property. /// public const int CURRENT_SCHEMA_VERSION = 1; /// /// Gets or sets the version of the stored form. /// public int SchemaVersion { get; set; } = CURRENT_SCHEMA_VERSION; /// /// Gets or sets the draft the person has not confirmed yet, or null while there is none. /// public BflResultVersion? Draft { get; set; } /// /// Gets or sets the version the person confirmed, or null while there is none. /// public BflResultVersion? Confirmed { get; set; } /// /// Starts a draft from the confirmed version, so that the person can edit it; a draft which is there already /// stays as it is. /// public void Edit() { if (this.Draft is not null || this.Confirmed is not { } confirmed) return; this.Draft = new BflResultVersion { Text = confirmed.Text, WorkStateRevisions = new(confirmed.WorkStateRevisions), ChangedAtUtc = confirmed.ChangedAtUtc, }; } /// /// Confirms the draft with the text the person approved: it becomes the version to export, and the draft is gone. /// /// The text of the draft as the person approved it. /// When the person confirmed it. /// There is no draft to confirm. public void Confirm(string text, DateTimeOffset confirmedAtUtc) { if (this.Draft is not { } draft) throw new InvalidOperationException("There is no draft of the result to confirm."); this.Confirmed = new BflResultVersion { Text = text, WorkStateRevisions = new(draft.WorkStateRevisions), ChangedAtUtc = confirmedAtUtc, }; this.Draft = null; } }