import {
  initialButtonPermissions,
  initialMenuTree,
  type MenuPermissionNode as PermissionMenuNode,
} from '../permission/mock';

export interface RoleItem {
  id: string;
  name: string;
  code: string;
  userCount: number;
  enabled: boolean;
  description: string;
  updatedAt: string;
  menuKeys: string[];
  buttonKeys: string[];
}

export interface MenuPermissionNode {
  key: string;
  title: string;
  children?: MenuPermissionNode[];
}

const toRoleMenuTree = (nodes: PermissionMenuNode[]): MenuPermissionNode[] =>
  nodes.map(node => ({
    key: node.key,
    title: node.title,
    children: node.children ? toRoleMenuTree(node.children) : undefined,
  }));

export const menuPermissionTree = toRoleMenuTree(initialMenuTree);

export const buttonPermissionOptions = initialButtonPermissions.map(item => ({
  label: item.code,
  value: item.code,
}));

export const initialRoles: RoleItem[] = [
  {
    id: 'role-1',
    name: '超级管理员',
    code: 'ROLE_ADMIN',
    userCount: 3,
    enabled: true,
    description: '拥有系统全部权限',
    updatedAt: '2026-07-20 10:00',
    menuKeys: ['1', '2', '2-1', '2-2', '2-3', '2-4', '2-5', '3', '3-1', '3-2', '3-3'],
    buttonKeys: initialButtonPermissions.map(item => item.code),
  },
  {
    id: 'role-2',
    name: '运营',
    code: 'ROLE_OPERATOR',
    userCount: 5,
    enabled: true,
    description: '负责模型与用户日常运营',
    updatedAt: '2026-07-22 15:30',
    menuKeys: ['1', '2', '2-1', '2-2', '2-3', '2-5', '3', '3-1', '3-2'],
    buttonKeys: ['system:user:add', 'system:user:edit', 'llm:models:add'],
  },
  {
    id: 'role-3',
    name: '只读',
    code: 'ROLE_VIEWER',
    userCount: 4,
    enabled: true,
    description: '仅可查看数据，不可修改',
    updatedAt: '2026-07-18 09:12',
    menuKeys: ['1', '2', '2-1', '2-3'],
    buttonKeys: [],
  },
];
