import { invoke } from '@tauri-apps/api/core';
import { ApiResponse } from '../types';

interface VideoCompositeRequest {
  video_paths: string[];
  audio_path?: string;
  cover_path?: string;
  output_path: string;
}

/**
 * 压制成片 API（走 Tauri IPC 直接命令）
 */
export const compositeApi = {
  /**
   * 执行压制成片
   */
  synthesis: async (request: VideoCompositeRequest): Promise<string> => {
    const response = await invoke<ApiResponse<string>>('video_composite_synthesis', { request });
    if (!response || typeof response !== 'object') {
      throw new Error('IPC request returned invalid response');
    }
    if ('code' in response && response.code !== 200) {
      throw new Error(response.message || '压制成片失败');
    }
    return response.data as string;
  },
};
