import { apiRequest } from './api.js'

export function fetchEmployees(params = {}) {
  const search = new URLSearchParams()

  if (params.status && params.status !== '全部员工') {
    search.set('status', params.status)
  }

  if (params.keyword) {
    search.set('keyword', params.keyword)
  }

  const query = search.toString()
  return apiRequest(`/employees${query ? `?${query}` : ''}`)
}

export function fetchEmployeeMeta() {
  return apiRequest('/employees/meta')
}

export function fetchEmployeeDetail(employeeId) {
  return apiRequest(`/employees/${employeeId}`)
}

export function updateEmployee(employeeId, payload) {
  return apiRequest(`/employees/${employeeId}`, {
    method: 'PATCH',
    body: JSON.stringify(payload)
  })
}

export function disableEmployee(employeeId) {
  return apiRequest(`/employees/${employeeId}/disable`, {
    method: 'POST'
  })
}
