/**
 * 设备管理相关API
 */

import { get, post, put } from '@/utils/request';

export interface DeviceQueryParams {
  page?: number;
  pageSize?: number;
  deviceId?: string;
  shopId?: number;
  status?: number;
  storeName?: string;
  keyword?: string;
}

export interface DeviceListResponse {
  list: any[];
  total: number;
  page: number;
  pageSize: number;
}

/**
 * 获取设备列表
 */
export async function getDeviceList(params: DeviceQueryParams = {}): Promise<DeviceListResponse> {
  return get('/devices/list', params);
}

/**
 * 获取设备详情
 */
export async function getDeviceDetail(deviceId: string): Promise<any> {
  return get(`/devices/${deviceId}`);
}

/**
 * 获取设备统计数据
 */
export async function getDeviceStats(): Promise<any> {
  return get('/devices/statistics');
}

/**
 * 远程开门
 */
export async function openDeviceDoor(deviceId: string, doorIndex?: string): Promise<void> {
  await post(`/devices/${deviceId}/open`, { doorIndex: doorIndex || 'A' });
}

/**
 * 设置设备温度
 */
export async function setDeviceTemperature(deviceId: string, temperature: number): Promise<void> {
  await put(`/devices/${deviceId}/temperature`, { temperature });
}

/**
 * 设置设备音量
 */
export async function setDeviceVolume(deviceId: string, volume: number): Promise<void> {
  await put(`/devices/${deviceId}/volume`, { volume });
}

/**
 * 获取设备商品配置
 */
export async function getDeviceProductConfig(deviceId: string): Promise<any> {
  return get(`/devices/${deviceId}/product-config`);
}

/**
 * 保存设备商品配置
 */
export async function saveDeviceProductConfig(deviceId: string, data: any): Promise<any> {
  return post(`/devices/${deviceId}/product-config`, data);
}

/**
 * 获取设备门记录
 */
export async function getDeviceDoorRecords(deviceId: string, params: { page?: number; pageSize?: number } = {}): Promise<any> {
  return get(`/devices/${deviceId}/door-records`, params);
}
