using System.Data.Common; using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services; using ZB.MOM.WW.ScadaBridge.Commons.Messages.Notification; using ZB.MOM.WW.ScadaBridge.Commons.Types; using ZB.MOM.WW.ScadaBridge.Commons.Types.Scripts; namespace ZB.MOM.WW.ScadaBridge.ScriptAnalysis; /// /// M3.1: a compile-only globals type that mirrors the real SiteRuntime /// ScriptGlobals (+ ScriptRuntimeContext helper surface) /// member-for-member, so a real instance / shared / on-trigger-handler script /// BINDS against it at design time. It is NEVER executed — every member body /// throws or returns default. The /// design-time deploy gate (M3.5) compiles candidate scripts against this type /// via /// to catch undefined symbols and signature mismatches without touching the /// site runtime. /// /// /// Keeping this surface faithful is enforced by the /// RoslynScriptCompilerTests "representative real script" corpus — if a /// member or signature drifts from the runtime ScriptGlobals, that test /// fails. /// /// public sealed class ScriptCompileSurface { private const string CompileOnly = "compile-only surface"; /// Mirrors ScriptGlobals.Instance. public CompileInstance Instance { get; set; } = null!; /// Mirrors ScriptGlobals.Parameters. public ScriptParameters Parameters { get; set; } = new(); /// Mirrors ScriptGlobals.CancellationToken. public CancellationToken CancellationToken { get; set; } /// Mirrors ScriptGlobals.Alarm. public AlarmContext? Alarm { get; set; } /// Mirrors ScriptGlobals.Scope. public ScriptScope Scope { get; set; } = ScriptScope.Root; /// Mirrors ScriptGlobals.ExternalSystem (delegates to Instance). public CompileExternalSystem ExternalSystem => Instance.ExternalSystem; /// Mirrors ScriptGlobals.Database. public CompileDatabase Database => Instance.Database; /// Mirrors ScriptGlobals.Notify. public CompileNotify Notify => Instance.Notify; /// Mirrors ScriptGlobals.Scripts. public CompileScripts Scripts => Instance.Scripts; /// Mirrors ScriptGlobals.Attributes. public CompileAttributeAccessor Attributes => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptGlobals.Children. public CompileChildrenAccessor Children => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptGlobals.Parent. public CompileCompositionAccessor? Parent => throw new NotSupportedException(CompileOnly); /// Compile-only mirror of ScriptRuntimeContext (the Instance global). public sealed class CompileInstance { /// Mirrors ScriptRuntimeContext.GetAttribute. public Task GetAttribute(string attributeName) => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptRuntimeContext.SetAttribute. public Task SetAttribute(string attributeName, string value) => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptRuntimeContext.CallScript. public Task CallScript(string scriptName, object? parameters = null) => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptRuntimeContext.ExternalSystem. public CompileExternalSystem ExternalSystem => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptRuntimeContext.Database. public CompileDatabase Database => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptRuntimeContext.Notify. public CompileNotify Notify => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptRuntimeContext.Scripts. public CompileScripts Scripts => throw new NotSupportedException(CompileOnly); /// Mirrors ScriptRuntimeContext.Tracking. public CompileTracking Tracking => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of ScriptRuntimeContext.ExternalSystemHelper. public sealed class CompileExternalSystem { /// Mirrors ExternalSystemHelper.Call. public Task Call( string systemName, string methodName, IReadOnlyDictionary? parameters = null, CancellationToken cancellationToken = default) => throw new NotSupportedException(CompileOnly); /// Mirrors ExternalSystemHelper.CachedCall. public Task CachedCall( string systemName, string methodName, IReadOnlyDictionary? parameters = null, CancellationToken cancellationToken = default) => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of ScriptRuntimeContext.DatabaseHelper. public sealed class CompileDatabase { /// Mirrors DatabaseHelper.Connection. public Task Connection(string name, CancellationToken cancellationToken = default) => throw new NotSupportedException(CompileOnly); /// Mirrors DatabaseHelper.CachedWrite. public Task CachedWrite( string name, string sql, IReadOnlyDictionary? parameters = null, CancellationToken cancellationToken = default) => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of ScriptRuntimeContext.NotifyHelper. public sealed class CompileNotify { /// Mirrors NotifyHelper.To. public CompileNotifyTarget To(string listName) => throw new NotSupportedException(CompileOnly); /// Mirrors NotifyHelper.Status. public Task Status(string notificationId) => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of ScriptRuntimeContext.NotifyTarget. public sealed class CompileNotifyTarget { /// Mirrors NotifyTarget.Send. public Task Send(string subject, string message, CancellationToken cancellationToken = default) => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of ScriptRuntimeContext.ScriptCallHelper. public sealed class CompileScripts { /// Mirrors ScriptCallHelper.CallShared. public Task CallShared( string scriptName, object? parameters = null, CancellationToken cancellationToken = default) => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of ScriptRuntimeContext.TrackingHelper. public sealed class CompileTracking { /// Mirrors TrackingHelper.Status. public Task Status( TrackedOperationId trackedOperationId, CancellationToken cancellationToken = default) => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of AttributeAccessor. public sealed class CompileAttributeAccessor { /// Mirrors AttributeAccessor.this[string]. public object? this[string key] { get => throw new NotSupportedException(CompileOnly); set => throw new NotSupportedException(CompileOnly); } /// Mirrors AttributeAccessor.GetAsync. public Task GetAsync(string key) => throw new NotSupportedException(CompileOnly); /// Mirrors AttributeAccessor.SetAsync. public Task SetAsync(string key, object? value) => throw new NotSupportedException(CompileOnly); /// Mirrors AttributeAccessor.Resolve. public string Resolve(string key) => throw new NotSupportedException(CompileOnly); /// Mirrors AttributeAccessor.WaitAsync. public Task WaitAsync(string key, object? targetValue, TimeSpan timeout, bool requireGoodQuality = false) => throw new NotSupportedException(CompileOnly); public Task WaitAsync(string key, Func predicate, TimeSpan timeout, bool requireGoodQuality = false) => throw new NotSupportedException(CompileOnly); /// Mirrors AttributeAccessor.WaitForAsync. public Task WaitForAsync(string key, object? targetValue, TimeSpan timeout, bool requireGoodQuality = false) => throw new NotSupportedException(CompileOnly); public Task WaitForAsync(string key, Func predicate, TimeSpan timeout, bool requireGoodQuality = false) => throw new NotSupportedException(CompileOnly); /// Mirrors AttributeAccessor.WriteBatchAndWaitAsync. public Task WriteBatchAndWaitAsync(IReadOnlyDictionary values, string flagKey, object? flagValue, string responseKey, object? responseValue, TimeSpan timeout) => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of ChildrenAccessor. public sealed class CompileChildrenAccessor { /// Mirrors ChildrenAccessor.this[string]. public CompileCompositionAccessor this[string compositionName] => throw new NotSupportedException(CompileOnly); } /// Compile-only mirror of CompositionAccessor. public sealed class CompileCompositionAccessor { /// Mirrors CompositionAccessor.Attributes. public CompileAttributeAccessor Attributes => throw new NotSupportedException(CompileOnly); /// Mirrors CompositionAccessor.CallScript. public Task CallScript(string scriptName, object? parameters = null) => throw new NotSupportedException(CompileOnly); /// Mirrors CompositionAccessor.ResolveScript. public string ResolveScript(string scriptName) => throw new NotSupportedException(CompileOnly); /// Mirrors CompositionAccessor.Path. public string Path => throw new NotSupportedException(CompileOnly); } }