/**
 * 设备相关API
 */

import { post } from '../utils/request';

/**
 * 扫码开门请求参数
 */
export interface ScanDoorRequest {
  deviceId: string;
  userId: string;
}

/**
 * 扫码开门响应数据
 */
export interface ScanDoorResponse {
  doorOpened: boolean;
  outTradeNo: string;
  orderNo: string;
  deviceId: string;
  doorIndex: number;
}

/**
 * 设备状态响应数据
 */
export interface DeviceStatusResponse {
  deviceId: string;
  status: string;
  isOnline: boolean;
}

/**
 * 扫码开门
 * @param deviceId 设备ID（从二维码中解析）
 */
export const scanDoor = (deviceId: string): Promise<ScanDoorResponse> => {
  return post<ScanDoorResponse>('/device/scan-open', {
    deviceId
  });
};

/**
 * 检查设备状态
 * @param deviceId 设备ID
 */
export const checkDeviceStatus = (deviceId: string): Promise<DeviceStatusResponse> => {
  return post<DeviceStatusResponse>('/device/status', {
    deviceId
  });
};
