import { canUserDownloadMaterial, isSuperAdmin, isSystemAdmin, } from '@/lib/department-permission' export interface SkuRouteSessionUser { id: string role?: string | null department?: string | null managedDepartment?: string | null isSuperAdmin?: boolean | null } export interface SkuRouteMaterial { userId: string materialType: string } export async function canManageSkuMaterial( user: SkuRouteSessionUser, material: Pick, ): Promise { if (material.userId === user.id || isSystemAdmin(user.role) || user.isSuperAdmin === true) { return true } return isSuperAdmin(user.id) } export async function canDownloadSkuMaterial( user: SkuRouteSessionUser, material: SkuRouteMaterial, ): Promise { return canUserDownloadMaterial( user.department, user.role || 'USER', user.managedDepartment, material.materialType, user.id, ) }