import request from '@/utils/request';
import type { ApiResult } from '@/api';

const LED_API_URL = import.meta.env.DEV
  ? 'http://127.0.0.1:9200/api'         // 开发环境走 Vite 代理, 避免跨域
  : 'http://16.1.3.234:9200/api';

export async function stopReplace(data: any) {
  const res = await request.post<ApiResult<unknown>>(
    LED_API_URL + '/led/bme/stop-replace',
    data,
    { baseURL: '' }   // 绕过全局 baseURL, 直接访问 LED 后端
  );
  if (res.data.code === 0) {
    const data = res.data.data;
    return data || [];
  }
  return Promise.reject(new Error(res.data.message));
}

export async function numberReplace(data: any) {
  const res = await request.post<ApiResult<unknown>>(
    LED_API_URL + '/led/bme/number-sources',
    data,
    { baseURL: '' }   // 绕过全局 baseURL, 直接访问 LED 后端
  );
  if (res.data.code === 0) {
    const data = res.data.data;
    return data || [];
  }
  return Promise.reject(new Error(res.data.message));
}
