using ScadaLink.Commons.Types; namespace ScadaLink.Commons.Interfaces.Services; /// /// Interface for invoking external system HTTP APIs. /// Implemented by ExternalSystemGateway, consumed by ScriptRuntimeContext. /// public interface IExternalSystemClient { /// /// Synchronous call to an external system. All failures returned to caller. /// Task CallAsync( string systemName, string methodName, IReadOnlyDictionary? parameters = null, CancellationToken cancellationToken = default); /// /// Attempt immediate delivery; on transient failure, hand to S&F engine. /// Permanent failures returned to caller. /// Task CachedCallAsync( string systemName, string methodName, IReadOnlyDictionary? parameters = null, string? originInstanceName = null, CancellationToken cancellationToken = default); } /// /// Result of an external system call. /// public record ExternalCallResult( bool Success, string? ResponseJson, string? ErrorMessage, bool WasBuffered = false) { private dynamic? _response; private bool _responseParsed; /// /// Parsed response as a dynamic object. Returns null if ResponseJson is null or empty. /// Access properties directly: result.Response.result, result.Response.items[0].name, etc. /// public dynamic? Response { get { if (!_responseParsed) { _response = string.IsNullOrEmpty(ResponseJson) ? null : new DynamicJsonElement(System.Text.Json.JsonDocument.Parse(ResponseJson).RootElement); _responseParsed = true; } return _response; } } }