using ZB.MOM.WW.ScadaBridge.Commons.Entities.Schemas; namespace ZB.MOM.WW.ScadaBridge.CentralUI.Services; /// /// Outcome of a single schema-library mutation dispatch (create / update / delete). /// Wraps either success or a human-readable server error (a duplicate-name guard, an /// invalid-JSON validation failure, or a not-found) so the schema-library page can /// render an inline result rather than reasoning about transport exceptions or the /// three management response shapes. Mirrors . /// /// Whether the mutation succeeded. /// A human-readable error message when is false; otherwise null. public record SchemaLibraryActionResult(bool Success, string? Error) { /// Creates a successful result. /// A successful . public static SchemaLibraryActionResult Ok() => new(true, null); /// Creates a failed result carrying . /// The human-readable failure (typically a server guard / validation message). /// A failed . public static SchemaLibraryActionResult Fail(string error) => new(false, error); } /// /// CentralUI facade over the schema-library CRUD management commands. Every /// mutation (CreateSharedSchemaCommand / UpdateSharedSchemaCommand / /// DeleteSharedSchemaCommand) and the list query is dispatched to the central /// ManagementActor through the in-process ManagementActorHolder seam — the /// SAME Ask path the HTTP /management endpoint uses — so the server remains the /// single enforcer of the Designer role gate, the unique-name guard, and JSON-Schema /// validation. The page re-implements none of that: it lists, authors via /// SchemaBuilder, and SUBMITS commands; any guard / validation failure comes back /// as a classified . /// /// /// The current Blazor principal is projected to an AuthenticatedUser so the /// server's role gate runs against the real identity. Mirrors /// IDataConnectionMoveService / ISecuredWriteService. /// public interface ISchemaLibraryService { /// /// Lists every library schema (name-ordered) via the read-gated /// ListSharedSchemasCommand. A read failure yields an empty list (logged) so /// the page renders gracefully. /// /// Cancellation token. /// A task resolving to the library entries, or an empty list on failure. Task> ListAsync(CancellationToken cancellationToken = default); /// /// Creates a library schema via the Designer-gated CreateSharedSchemaCommand. /// /// The unique schema name. /// An optional scope discriminator (null = global). /// The JSON Schema document text. /// Cancellation token. /// A task resolving to a classified create outcome. Task CreateAsync( string name, string? scope, string schemaJson, CancellationToken cancellationToken = default); /// /// Updates a library schema via the Designer-gated UpdateSharedSchemaCommand. /// /// Primary key of the schema to update. /// The (possibly renamed) unique schema name. /// An optional scope discriminator (null = global). /// The JSON Schema document text. /// Cancellation token. /// A task resolving to a classified update outcome. Task UpdateAsync( int id, string name, string? scope, string schemaJson, CancellationToken cancellationToken = default); /// /// Deletes a library schema via the Designer-gated DeleteSharedSchemaCommand. /// /// Primary key of the schema to delete. /// Cancellation token. /// A task resolving to a classified delete outcome. Task DeleteAsync(int id, CancellationToken cancellationToken = default); }