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

export function listUser(
  params?: PageQuery & Partial<User> & { deptId?: number },
  config?: AxiosRequestConfig
): Promise<PageResult<User>> {
  return http.get('/system/user/list', { params, ...config })
}

export function getUser(id: number): Promise<User> {
  return http.get(`/system/user/${id}`)
}

export function addUser(data: Partial<User>): Promise<void> {
  return http.post('/system/user', data)
}

export function updateUser(data: Partial<User>): Promise<void> {
  return http.put('/system/user', data)
}

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

export function assignUserRoles(id: number, roleIds: number[]): Promise<void> {
  return http.put(`/system/user/${id}/roles`, { roleIds })
}

export function bindWeCom(id: number, data: { wecomUserId?: string; wecomRemindEnabled?: number }): Promise<void> {
  return http.put(`/system/user/${id}/wecom`, data)
}
