feat(uns): scripted-alarm CRUD in IUnsTreeService for the equipment Alarms tab

This commit is contained in:
Joseph Doherty
2026-06-11 14:25:59 -04:00
parent 7c22861598
commit 705ed6234f
5 changed files with 226 additions and 0 deletions
@@ -457,4 +457,59 @@ public interface IUnsTreeService
/// <param name="ct">A token to cancel the operation.</param>
/// <returns>Success, a missing-row failure, or a concurrency failure.</returns>
Task<(bool Ok, string? Error)> UpdateScriptSourceAsync(string scriptId, string sourceCode, byte[] rowVersion, CancellationToken ct = default);
/// <summary>
/// Loads the scripted alarms owned by a single equipment as flat row projections for the equipment
/// page's Alarms tab table, ordered by Name. Each row carries the display columns plus the
/// <c>ScriptedAlarmId</c> the table uses to open the edit modal. Reads untracked. Returns an empty
/// list when the equipment has no scripted alarms.
/// </summary>
/// <param name="equipmentId">The equipment whose scripted alarms to load.</param>
/// <param name="ct">A token to cancel the load.</param>
/// <returns>The equipment's scripted-alarm rows ordered by Name; empty if it has none.</returns>
Task<IReadOnlyList<EquipmentAlarmRow>> LoadAlarmsForEquipmentAsync(string equipmentId, CancellationToken ct = default);
/// <summary>
/// Loads a single scripted alarm projected for editing, or <c>null</c> if it no longer exists.
/// Reads untracked and captures the current concurrency token for last-write-wins saves.
/// </summary>
/// <param name="scriptedAlarmId">The scripted alarm to load.</param>
/// <param name="ct">A token to cancel the load.</param>
/// <returns>The scripted alarm's edit projection, or <c>null</c> when missing.</returns>
Task<ScriptedAlarmEditDto?> LoadScriptedAlarmAsync(string scriptedAlarmId, CancellationToken ct = default);
/// <summary>
/// Creates a new scripted alarm under an equipment. The <c>ScriptedAlarmId</c> is operator-typed
/// (not system-generated). Fails on a duplicate <c>ScriptedAlarmId</c>. Field validation (severity
/// range, required fields) is enforced client-side in the modal. On success the operator-typed id is
/// echoed back via <see cref="UnsMutationResult.CreatedId"/>.
/// </summary>
/// <param name="equipmentId">The owning equipment.</param>
/// <param name="input">The operator-editable scripted-alarm fields.</param>
/// <param name="ct">A token to cancel the operation.</param>
/// <returns>Success carrying the created id, or a duplicate-id failure.</returns>
Task<UnsMutationResult> CreateScriptedAlarmAsync(string equipmentId, ScriptedAlarmInput input, CancellationToken ct = default);
/// <summary>
/// Updates a scripted alarm's mutable fields (name, alarm type, severity, message template,
/// predicate script, and the historize/retain/enabled flags). The owning <c>EquipmentId</c> is
/// preserved (the Alarms tab fixes it). Uses last-write-wins optimistic concurrency on
/// <see cref="Configuration.Entities.ScriptedAlarm.RowVersion"/>.
/// </summary>
/// <param name="scriptedAlarmId">The scripted alarm to update.</param>
/// <param name="input">The new operator-editable scripted-alarm fields.</param>
/// <param name="rowVersion">The concurrency token the caller last read.</param>
/// <param name="ct">A token to cancel the operation.</param>
/// <returns>Success, a missing-row failure, or a concurrency failure.</returns>
Task<UnsMutationResult> UpdateScriptedAlarmAsync(string scriptedAlarmId, ScriptedAlarmInput input, byte[] rowVersion, CancellationToken ct = default);
/// <summary>
/// Deletes a scripted alarm. A missing row is treated as success (already gone). Uses last-write-wins
/// optimistic concurrency on <see cref="Configuration.Entities.ScriptedAlarm.RowVersion"/>.
/// </summary>
/// <param name="scriptedAlarmId">The scripted alarm to delete.</param>
/// <param name="rowVersion">The concurrency token the caller last read.</param>
/// <param name="ct">A token to cancel the operation.</param>
/// <returns>Success, a concurrency failure, or a delete-failed failure.</returns>
Task<UnsMutationResult> DeleteScriptedAlarmAsync(string scriptedAlarmId, byte[] rowVersion, CancellationToken ct = default);
}