import request from '@/utils/request';
import type { PermissionResponse, PermissionRequest, PermissionQuery } from './types';
import { Page } from '@/types/base';

const BASE_URL = '/api/v1/permission';

// 获取权限列表(分页)
export const getPermissions = (params?: PermissionQuery) =>
  request.get<Page<PermissionResponse>>(`${BASE_URL}/page`, { params });

// 获取权限列表(不分页,按菜单ID查询)
export const getPermissionsByMenuId = (menuId: number) =>
  request.get<PermissionResponse[]>(`${BASE_URL}/list`, { params: { menuId } });

// 获取单个权限
export const getPermission = (id: number) =>
  request.get<PermissionResponse>(`${BASE_URL}/${id}`);

// 创建权限
export const createPermission = (data: PermissionRequest) =>
  request.post<PermissionResponse>(`${BASE_URL}/create`, data);

// 更新权限
export const updatePermission = (id: number, data: PermissionRequest) =>
  request.put<PermissionResponse>(`${BASE_URL}/${id}`, data);

// 删除权限
export const deletePermission = (id: number) =>
  request.delete(`${BASE_URL}/${id}`);

