using ZB.MOM.WW.OtOpcUa.Commons.Types;

namespace ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin;

/// <summary>
///     The shelve action an operator requested. Maps 1:1 onto the engine-side <c>Operation</c>
///     strings the <c>ScriptedAlarmHostActor</c> dispatches on
///     (<c>OneShotShelve</c> / <c>TimedShelve</c> / <c>Unshelve</c>).
/// </summary>
public enum ShelveKind
{
    /// <summary>Shelve until the next clear (no timer). Maps to <c>Operation = "OneShotShelve"</c>.</summary>
    OneShot,

    /// <summary>Shelve until an absolute instant. Maps to <c>Operation = "TimedShelve"</c>; carries <c>UnshelveAtUtc</c>.</summary>
    Timed,

    /// <summary>Remove an existing shelve. Maps to <c>Operation = "Unshelve"</c>.</summary>
    Unshelve,
}

/// <summary>
///     AdminUI → AdminOperationsActor: shelve / unshelve one alarm on behalf of an operator. The admin
///     singleton maps <see cref="Kind"/> to the matching <c>Commons.OpcUa.AlarmCommand</c> operation
///     (<c>OneShotShelve</c> / <c>TimedShelve</c> / <c>Unshelve</c>), threading
///     <see cref="UnshelveAtUtc"/> for <see cref="ShelveKind.Timed"/>, and republishes it onto the
///     cluster <c>alarm-commands</c> topic, where the owning <c>ScriptedAlarmHostActor</c> filters by
///     ownership and drives the engine.
/// </summary>
/// <param name="AlarmId">The alarm's ScriptedAlarmId (the <c>AlarmTransitionEvent.AlarmId</c> shown on the row).</param>
/// <param name="User">The authenticated operator who triggered the shelve.</param>
/// <param name="Kind">Which shelve action to perform.</param>
/// <param name="UnshelveAtUtc">
///     For <see cref="ShelveKind.Timed"/>, the absolute UTC instant the shelve auto-expires; null for
///     <see cref="ShelveKind.OneShot"/> and <see cref="ShelveKind.Unshelve"/>.
/// </param>
/// <param name="Comment">Optional free-text comment supplied with the shelve; null when none.</param>
/// <param name="CorrelationId">Round-trip correlation token.</param>
public sealed record ShelveAlarmCommand(
    string AlarmId,
    string User,
    ShelveKind Kind,
    DateTime? UnshelveAtUtc,
    string? Comment,
    CorrelationId CorrelationId);

/// <summary>Reply for <see cref="ShelveAlarmCommand"/>.</summary>
/// <param name="Ok">True iff the command was published without error.</param>
/// <param name="Message">Failure reason; null on success.</param>
/// <param name="CorrelationId">Echoes the request's correlation token.</param>
public sealed record ShelveAlarmResult(
    bool Ok,
    string? Message,
    CorrelationId CorrelationId);
