import { PRD_INTEGRATION_MANAGE, PRD_INTEGRATION_VIEW } from "@/lib/admin-prd";

export type AdminPermissionBundleKey = "view" | "manage" | "audit" | "export" | "privilege";

export type AdminPageKey = "integration-sites";

/**
 * “页面权限包”是把运营/管理员能理解的词汇（查看/管理/审核/导出/特权）
 * 映射到系统真实用的 `prd.*` 权限 slug。
 *
 * 目前只落地 integration-sites；其它页面按同样方式逐步接入。
 */
export const ADMIN_PERMISSION_BUNDLES = {
  "integration-sites": {
    view: [PRD_INTEGRATION_VIEW] as const,
    manage: [PRD_INTEGRATION_MANAGE] as const,
    audit: [] as const,
    // 导出接口的资源鉴权仍落在 view/manage，因此这里复用 view。
    export: [PRD_INTEGRATION_VIEW] as const,
    privilege: [] as const,
  },
} satisfies Record<AdminPageKey, Record<AdminPermissionBundleKey, readonly string[]>>;

export const ADMIN_PAGE_REQUIRED_ANY = {
  "integration-sites": [
    ...ADMIN_PERMISSION_BUNDLES["integration-sites"].view,
    ...ADMIN_PERMISSION_BUNDLES["integration-sites"].manage,
  ] as const,
} satisfies Record<AdminPageKey, readonly string[]>;

export function getAdminPageRequiredAny(page: AdminPageKey): readonly string[] {
  return ADMIN_PAGE_REQUIRED_ANY[page];
}

export function getAdminPageBundle(
  page: AdminPageKey,
  bundle: AdminPermissionBundleKey,
): readonly string[] {
  return ADMIN_PERMISSION_BUNDLES[page][bundle] ?? [];
}

