using Socialize.Api.Modules.CalendarIntegrations.Data; namespace Socialize.Api.Modules.CalendarIntegrations.Services; public static class CalendarSourceRules { public static readonly string[] SupportedScopes = [ CalendarSourceScopes.Organization, CalendarSourceScopes.Workspace, CalendarSourceScopes.User, ]; public static readonly string[] SupportedInheritanceModes = [ CalendarSourceInheritanceModes.Required, CalendarSourceInheritanceModes.Optional, ]; public static bool IsSupportedScope(string? scope) { return SupportedScopes.Contains(scope?.Trim(), StringComparer.Ordinal); } public static bool IsSupportedInheritanceMode(string? inheritanceMode) { return SupportedInheritanceModes.Contains(inheritanceMode?.Trim(), StringComparer.Ordinal); } public static bool IsInheritedOrganizationSource(CalendarSource source, Guid workspaceOrganizationId) { return source.Scope == CalendarSourceScopes.Organization && source.OrganizationId == workspaceOrganizationId; } public static bool CanManageScope( string scope, bool canManageOrganizationCalendars, bool canManageWorkspaceCalendars, Guid currentUserId, Guid? sourceUserId) { return scope switch { CalendarSourceScopes.Organization => canManageOrganizationCalendars, CalendarSourceScopes.Workspace => canManageWorkspaceCalendars, CalendarSourceScopes.User => sourceUserId == currentUserId, _ => false, }; } }