import api from '@/utils/http'

// 1. 获取用户列表
export function fetchGetUserList(params: Api.SystemManage.UserSearchParams) {
  return api.get<Api.SystemManage.UserListResponse>({
    url: '/api/admin/v1/users',
    params
  })
}

// 2. 获取用户详情
export function fetchGetUserDetail(userId: string, includeDeleted?: boolean) {
  return api.get<Api.SystemManage.UserDetailDto>({
    url: `/api/admin/v1/users/${userId}`,
    params: includeDeleted ? { includeDeleted } : undefined
  })
}

// 3. 创建用户
export function fetchCreateUser(command: Api.SystemManage.CreateIdentityUserCommand) {
  return api.post<Api.SystemManage.UserDetailDto>({
    url: '/api/admin/v1/users',
    data: command
  })
}

// 4. 更新用户
export function fetchUpdateUser(
  userId: string,
  command: Api.SystemManage.UpdateIdentityUserCommand
) {
  return api.put<Api.SystemManage.UserDetailDto>({
    url: `/api/admin/v1/users/${userId}`,
    data: command
  })
}

// 5. 删除用户
export function fetchDeleteUser(userId: string) {
  return api.del<boolean>({
    url: `/api/admin/v1/users/${userId}`
  })
}

// 6. 恢复用户
export function fetchRestoreUser(userId: string) {
  return api.post<boolean>({
    url: `/api/admin/v1/users/${userId}/restore`
  })
}

// 7. 更新用户状态
export function fetchChangeUserStatus(
  userId: string,
  command: Api.SystemManage.ChangeIdentityUserStatusCommand
) {
  return api.put<boolean>({
    url: `/api/admin/v1/users/${userId}/status`,
    data: command
  })
}

// 8. 重置用户密码
export function fetchResetUserPassword(userId: string) {
  return api.post<Api.SystemManage.ResetIdentityUserPasswordResult>({
    url: `/api/admin/v1/users/${userId}/password-reset`
  })
}

// 9. 批量用户操作
export function fetchBatchUserOperation(
  command: Api.SystemManage.BatchIdentityUserOperationCommand
) {
  return api.post<Api.SystemManage.BatchIdentityUserOperationResult>({
    url: '/api/admin/v1/users/batch',
    data: command
  })
}

// 10. 获取菜单列表
export function fetchGetMenuList() {
  return api.get<Api.Menu.MenuDefinitionDto[]>({
    url: '/api/admin/v1/menus'
  })
}

// 11. 获取菜单详情
export function fetchGetMenuDetail(menuId: string) {
  return api.get<Api.Menu.MenuDefinitionDto>({
    url: `/api/admin/v1/menus/${menuId}`
  })
}
