/**
 * 补货员管理 API（运营平台端）
 */
import { get, post, put, del } from '@/utils/request';

export interface ReplenisherQuery {
  page: number;
  pageSize: number;
  keyword?: string;
  status?: number;
}

export interface ReplenisherForm {
  id?: string;
  name: string;
  phone?: string;
  employeeId?: string;
  status?: number;
  wechatOpenid?: string;
}

export interface ReplenisherListResponse {
  list: any[];
  total: number;
}

/**
 * 分页查询补货员列表
 */
export function getReplenisherList(params: ReplenisherQuery): Promise<ReplenisherListResponse> {
  return get('/replenishers/list', params);
}

/**
 * 获取补货员详情
 */
export function getReplenisherById(id: string): Promise<any> {
  return get(`/replenishers/${id}`);
}

/**
 * 新增补货员
 */
export function createReplenisher(data: ReplenisherForm): Promise<void> {
  return post('/replenishers', data);
}

/**
 * 更新补货员
 */
export function updateReplenisher(id: string, data: Partial<ReplenisherForm>): Promise<void> {
  return put(`/replenishers/${id}`, data);
}

/**
 * 切换补货员状态
 */
export function updateReplenisherStatus(id: string, status: number): Promise<void> {
  return put(`/replenishers/${id}/status`, { status });
}

/**
 * 删除补货员
 */
export function deleteReplenisher(id: string): Promise<void> {
  return del(`/replenishers/${id}`);
}

/**
 * 获取补货员已绑定的设备列表
 */
export function getBoundDevices(id: string): Promise<string[]> {
  return get(`/replenishers/${id}/devices`);
}

/**
 * 绑定设备
 */
export function bindDevices(id: string, deviceIds: string[]): Promise<void> {
  return post(`/replenishers/${id}/devices`, { deviceIds });
}

/**
 * 解绑设备
 */
export function unbindDevice(replenisherId: string, deviceId: string): Promise<void> {
  return del(`/replenishers/${replenisherId}/devices/${deviceId}`);
}

/**
 * 生成微信绑定码
 */
export function generateBindingCode(id: string): Promise<{ bindingCode: string }> {
  return post(`/replenishers/${id}/binding-code`);
}
