/**
 * @ai-summary API client for user data import
 * @ai-context Uploads import archive, generates preview, executes import
 */

import { apiClient } from '../../../core/api/client';
import { ImportPreview, ImportResult } from '../types/import.types';

export const importApi = {
  /**
   * Generate preview of import data
   */
  getPreview: async (file: File): Promise<ImportPreview> => {
    const formData = new FormData();
    formData.append('file', file);

    const response = await apiClient.post('/user/import/preview', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
      timeout: 120000, // 2 minute timeout for large files
    });
    return response.data;
  },

  /**
   * Execute import with specified mode
   */
  executeImport: async (
    file: File,
    mode: 'merge' | 'replace'
  ): Promise<ImportResult> => {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('mode', mode);

    const response = await apiClient.post('/user/import', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
      },
      timeout: 120000, // 2 minute timeout for large imports
    });
    return response.data;
  },
};
