import { request } from "@/components/service/index";

export const MlflowService = {
  getRuns: (experimentId: string) => {
    return request.get("/api/mlflow/runs", {
      experimentId,
    });
  },

  getExperimentByName: (experimentName: string) => {
    return request.get("/api/mlflow/experiment", {
      experimentName,
    });
  },
  getExperimentRun: (runId: string) => {
    return request.get("/api/mlflow/run", {
      runId,
    });
  },

  artifact: (runId: string, path?: string) => {
    const params: Record<string, any> = {
      runId,
      run_id: runId,
    };
    if (path !== undefined) params.path = path;

    // 1차: /list 시도 → 404면 구(舊) 경로로 폴백
    return request
      .get("/api/mlflow/artifacts/list", params)
      .catch((err: any) => {
        if (err?.response?.status === 404) {
          return request.get("/api/mlflow/artifacts", params);
        }
        throw err;
      });
  },
};
