import { probeDecoderApi, probeMediaServerApi, probeNvrApi, probeSecurityBoxApi, probeSwitchApi, probeVideoServerApi, type NdmDeviceResultVO, type Station } from '@/apis';
import { DEVICE_TYPE_LITERALS, tryGetDeviceType } from '@/enums';

export const probeDeviceApi = async (device: NdmDeviceResultVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
  const { stationCode, signal } = options ?? {};
  const deviceType = tryGetDeviceType(device.deviceType);
  const deviceDbId = device.id;
  if (!deviceType || !deviceDbId) throw new Error('未知的设备');
  if (deviceType === DEVICE_TYPE_LITERALS.ndmDecoder) {
    await probeDecoderApi([deviceDbId], { stationCode, signal });
    return;
  }
  if (deviceType === DEVICE_TYPE_LITERALS.ndmNvr) {
    await probeNvrApi([deviceDbId], { stationCode, signal });
    return;
  }
  if (deviceType === DEVICE_TYPE_LITERALS.ndmSecurityBox) {
    await probeSecurityBoxApi([deviceDbId], { stationCode, signal });
    return;
  }
  if (deviceType === DEVICE_TYPE_LITERALS.ndmMediaServer) {
    await probeMediaServerApi([deviceDbId], { stationCode, signal });
    return;
  }
  if (deviceType === DEVICE_TYPE_LITERALS.ndmSwitch) {
    await probeSwitchApi([deviceDbId], { stationCode, signal });
    return;
  }
  if (deviceType === DEVICE_TYPE_LITERALS.ndmVideoServer) {
    await probeVideoServerApi([deviceDbId], { stationCode, signal });
    return;
  }
};
