using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
namespace ZB.MOM.WW.OtOpcUa.Configuration.Services;
///
/// CRUD surface for — the control-plane mapping from
/// LDAP groups to Admin UI roles. Consumed only by Admin UI code paths; the OPC UA
/// data-path evaluator MUST NOT depend on this interface (see the
/// Phase 6.2 compliance check on control/data-plane separation).
///
///
///
/// This service has no local-cache fallback: a DB outage during sign-in denies logins.
///
///
/// The Phase 6.1 ResilientConfigReader pipeline (timeout → retry →
/// fallback-to-sealed-snapshot) this was once expected to run behind was never wired to
/// anything and was deleted along with the rest of the dormant LiteDB local cache, which
/// ZB.MOM.WW.LocalDb supersedes. LocalDb caches the deployed-configuration artifact
/// for driver-role nodes; it does not currently cover admin-plane reads like this one.
/// Reviving the fallback means adding an admin-side cache on LocalDb, not restoring the
/// old pipeline.
///
///
public interface ILdapGroupRoleMappingService
{
/// List every mapping whose LDAP group matches one of .
///
/// Hot path — fires on every sign-in. The default EF implementation relies on the
/// IX_LdapGroupRoleMapping_Group index. The match is a SQL IN (…) whose
/// case-sensitivity is determined by the LdapGroup column collation. Case-insensitive
/// behaviour requires a case-insensitive (CI) server or column collation — this is a
/// deployment requirement. On a case-sensitive-collation server the lookup will silently
/// miss rows that differ only in case.
///
/// The LDAP groups to search for.
/// The cancellation token.
/// The mappings whose LDAP group matches one of .
Task> GetByGroupsAsync(
IEnumerable ldapGroups, CancellationToken cancellationToken);
/// Enumerate every mapping; Admin UI listing only.
/// The cancellation token.
/// Every LDAP group role mapping.
Task> ListAllAsync(CancellationToken cancellationToken);
/// Create a new grant.
///
/// Thrown when the proposed row violates an invariant (IsSystemWide inconsistent with
/// ClusterId, duplicate (group, cluster) pair, etc.) — ValidatedLdapGroupRoleMappingService
/// is the write surface that enforces these; the raw service here surfaces DB-level violations.
///
/// The LDAP group role mapping to create.
/// The cancellation token.
/// The created mapping row.
Task CreateAsync(LdapGroupRoleMapping row, CancellationToken cancellationToken);
/// Delete a mapping by its surrogate key.
/// The unique identifier of the mapping to delete.
/// The cancellation token.
/// A task that represents the asynchronous operation.
Task DeleteAsync(Guid id, CancellationToken cancellationToken);
}
/// Thrown when authoring violates an invariant.
public sealed class InvalidLdapGroupRoleMappingException : Exception
{
/// Initializes a new instance of the InvalidLdapGroupRoleMappingException.
/// The error message.
public InvalidLdapGroupRoleMappingException(string message) : base(message) { }
}