import {
  importAlarmHostApi,
  importCameraApi,
  importDecoderApi,
  importKeyboardApi,
  importMediaServerApi,
  importNvrApi,
  importSecurityBoxApi,
  importSwitchApi,
  importVideoServerApi,
  type Station,
} from '@/apis';
import { DEVICE_TYPE_LITERALS, type DeviceType } from '@/enums';

export const importDeviceApi = async (deviceType: DeviceType, file: File, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
  const apiRecord = {
    [DEVICE_TYPE_LITERALS.ndmAlarmHost]: importAlarmHostApi,
    [DEVICE_TYPE_LITERALS.ndmCamera]: importCameraApi,
    [DEVICE_TYPE_LITERALS.ndmDecoder]: importDecoderApi,
    [DEVICE_TYPE_LITERALS.ndmKeyboard]: importKeyboardApi,
    [DEVICE_TYPE_LITERALS.ndmMediaServer]: importMediaServerApi,
    [DEVICE_TYPE_LITERALS.ndmNvr]: importNvrApi,
    [DEVICE_TYPE_LITERALS.ndmSecurityBox]: importSecurityBoxApi,
    [DEVICE_TYPE_LITERALS.ndmSwitch]: importSwitchApi,
    [DEVICE_TYPE_LITERALS.ndmVideoServer]: importVideoServerApi,
  };

  const importApi = apiRecord[deviceType];
  if (!importApi) throw new Error('接口不存在');

  return importApi(file, options);
};
