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