namespace KArtSell.Modules.ModelOperations.Domain;

/// <summary>
/// Central fail-closed boundary for scheduled model operations. The scheduler may request evidence,
/// proposals or drills only; it may never mutate model/code/configuration, publish client advice,
/// submit broker orders or change a model lifecycle state.
/// </summary>
public static class ModelOperationExecutionBoundary
{
    public const string BoundaryCode = "EVIDENCE_ONLY_NO_AUTO_MODEL_OR_ORDER_MUTATION";

    public static void EnsureAllowed(ModelOperationDefinition definition)
    {
        ArgumentNullException.ThrowIfNull(definition);

        if (definition.AutomationMode is not (
            AutomationMode.EvaluationOnly or AutomationMode.ProposalOnly or AutomationMode.DrillOnly))
        {
            throw new InvalidOperationException($"Operation {definition.OperationCode} violates {BoundaryCode}.");
        }

        if (!definition.Queue.StartsWith("q-", StringComparison.Ordinal))
        {
            throw new InvalidOperationException($"Operation {definition.OperationCode} has an unapproved queue.");
        }
    }
}
