namespace Distribution.Features.Notifications;
public enum ScopeKind { Region, Route, Store }
///
/// Who a notification goes to. There is deliberately no "everyone" rule — every trigger must say who
/// needs to know. Scope coverage follows Region → Route → Store: a region scope covers its routes
/// and their stores, a route scope covers its stores.
///
public abstract record RecipientRule
{
/// These specific users (creator, driver, approver, route owner …).
public static RecipientRule Users(params Guid[] ids) => new UsersRule(ids);
/// Every active user whose role holds the permission code.
public static RecipientRule Permission(string code) => new PermissionRule(code);
/// Every active user whose scope covers the region / route / store.
public static RecipientRule Scope(ScopeKind kind, Guid id) => new ScopeRule(kind, id);
/// Users who hold the permission AND whose scope covers the region / route / store.
public static RecipientRule PermissionInScope(string code, ScopeKind kind, Guid id) =>
new PermissionInScopeRule(code, kind, id);
/// The user's supervisor (User.FK_ReportsToUserId).
public static RecipientRule ReportsTo(Guid userId) => new ReportsToRule(userId);
/// The owner of the route () or of the store's route ().
public static RecipientRule RouteOwner(ScopeKind kind, Guid id) => new RouteOwnerRule(kind, id);
}
public sealed record UsersRule(IReadOnlyCollection Ids) : RecipientRule;
public sealed record PermissionRule(string Code) : RecipientRule;
public sealed record ScopeRule(ScopeKind Kind, Guid Id) : RecipientRule;
public sealed record PermissionInScopeRule(string Code, ScopeKind Kind, Guid Id) : RecipientRule;
public sealed record ReportsToRule(Guid UserId) : RecipientRule;
public sealed record RouteOwnerRule(ScopeKind Kind, Guid Id) : RecipientRule;