import request from '@/utils/request';
import type { Page } from '@/types/base';
import type {
  FormDataQuery,
  FormDataResponse,
  FormDataSubmitRequest,
  FormDataUpdateRequest,
} from './types';

const BASE_URL = '/api/v1/forms/data';

/**
 * 分页查询表单数据列表
 */
export const getFormDataList = (params?: FormDataQuery) =>
  request.get<Page<FormDataResponse>>(`${BASE_URL}/page`, { params });

/**
 * 获取表单数据详情
 */
export const getFormDataById = (id: number) =>
  request.get<FormDataResponse>(`${BASE_URL}/${id}`);

/**
 * 提交表单数据
 */
export const submitFormData = (data: FormDataSubmitRequest) =>
  request.post<FormDataResponse>(BASE_URL, data);

/**
 * 更新表单数据
 */
export const updateFormData = (id: number, data: FormDataUpdateRequest) =>
  request.put<FormDataResponse>(`${BASE_URL}/${id}`, data);

/**
 * 删除表单数据
 */
export const deleteFormData = (id: number) =>
  request.delete(`${BASE_URL}/${id}`);

/**
 * 批量删除表单数据
 */
export const batchDeleteFormData = (ids: number[]) =>
  request.post(`${BASE_URL}/batch-delete`, { ids });

/**
 * 导出表单数据
 */
export const exportFormData = (params?: FormDataQuery) =>
  request.download(`${BASE_URL}/export`, undefined, { params });

