// src/components/service/management/DatasetService.ts
import { request } from "@/components/service/index";

export interface ExternalListQuery {
  ds_prj_idx: number;
  search_keyword?: string;
  grp_name?: string;
}
export interface ExternalDatasetItem {
  ds_dataset_name: string;
  ds_dataset_image_count: number;
  labelling_tool_kr: string;
  ds_dataset_base_path: string;
}
export interface SaveExternalDatasetPayload {
  datasetName: string;
  path: string;
  refId: number;
  refType: "DATASET";
  title: string;
  description?: string;
  version: number;
  regUserId: string;
  projectId: number;
}

export const DatasetService = {
  listExternal(query: ExternalListQuery) {
    return request.get("/api/datasets/list", query as any);
  },
  saveExternal(payload: SaveExternalDatasetPayload) {
    const params = new URLSearchParams();
    (
      Object.entries(payload) as [keyof SaveExternalDatasetPayload, any][]
    ).forEach(([k, v]) => {
      if (v !== undefined && v !== null) params.append(k, String(v));
    });

    return request.post(
      `/api/datasets/dataset/save?${params.toString()}`,
      null,
    );
  },
};
