import { http } from '@/api/request'
import type { Role, User } from '@/types/system'
import type { PageQuery, PageResult } from '@/types/api'

export function listRole(params?: PageQuery & Partial<Role> & { deptId?: number }): Promise<PageResult<Role>> {
  return http.get('/system/role/list', { params })
}

export function getRole(id: number): Promise<Role> {
  return http.get(`/system/role/${id}`)
}

export function addRole(data: Partial<Role>): Promise<void> {
  return http.post('/system/role', data)
}

export function updateRole(data: Partial<Role>): Promise<void> {
  return http.put('/system/role', data)
}

export function deleteRole(id: number): Promise<void> {
  return http.delete(`/system/role/${id}`)
}

/** 查询拥有某角色的用户列表（转办选人） */
export function listUsersByRole(roleId: number): Promise<User[]> {
  return http.get(`/system/role/${roleId}/users`)
}
