import { request } from '@/utils/axios';

// 分页参数类型
export interface PageParam {
  pageNo?: number;
  pageSize?: number;
  [key: string]: any;
}

// 角色页面保存请求 VO
export interface RolePageSaveReqVO {
  id: number;
  roleId: number;
  roleName: string;
  pageType?: number;
}

// 页面UI组件保存请求 VO
export interface PageUiComponentSaveReqVO {
  id: number;
  pageId: number;
  componentId: number;
  componentRow?: string;
  componentColumn?: string;
}

// 角色页面管理 API
export const rolePageApi = {
  // 查询角色页面数据列表
  getRolePagePage: async (params?: PageParam) => {
    return await request.get({ url: '/sys/role-page/getRolePagePage', params });
  },

  // 获取角色数据详细信息
  selectRolePageById: async (id: number) => {
    return await request.get({ url: '/sys/role-page/selectRolePageById', params: { id } });
  },

  // 创建角色页面
  insertRolePage: async (data: RolePageSaveReqVO) => {
    return await request.post({ url: '/sys/role-page/insertRolePage', data });
  },

  // 更新角色页面
  updateRolePage: async (data: RolePageSaveReqVO) => {
    return await request.put({ url: '/sys/role-page/updateRolePage', data });
  },

  // 删除角色页面数据
  deleteRolePageList: async (ids: number[]) => {
    return await request.delete({ url: `/sys/role-page/deleteRolePageList?ids=${ids.join(',')}` });
  },
};

// 驾驶舱页面和组件关联 API
export const pageUiComponentApi = {
  // 获得分页数据
  getPageUiComponentPage: async (params?: PageParam) => {
    return await request.get({ url: '/sys/page-ui-component/getPageUiComponentPage', params });
  },

  // 获得详情数据
  selectPageUiComponentById: async (id: number) => {
    return await request.get({ url: '/sys/page-ui-component/selectPageUiComponentById', params: { id } });
  },

  // 创建页面和组件关联
  insertPageUiComponent: async (data: PageUiComponentSaveReqVO) => {
    return await request.post({ url: '/sys/page-ui-component/insertPageUiComponent', data });
  },

  // 修改页面和组件关联
  updatePageUiComponent: async (data: PageUiComponentSaveReqVO) => {
    return await request.put({ url: '/sys/page-ui-component/updatePageUiComponent', data });
  },

  // 批量删除
  deletePageUiComponentList: async (ids: number[]) => {
    return await request.delete({ url: `/sys/page-ui-component/deletePageUiComponentList?ids=${ids.join(',')}` });
  },
};

