import { request } from "./client";
import type { TraceDetailResponse, TraceListResponse } from "../types/trace";

export const traceApi = {
  fetchTraces(params?: { status?: string; mode?: string; limit?: number }) {
    const query = new URLSearchParams();
    if (params?.status) query.set("status", params.status);
    if (params?.mode) query.set("mode", params.mode);
    if (typeof params?.limit === "number") query.set("limit", String(params.limit));
    const suffix = query.toString() ? `?${query.toString()}` : "";
    return request<TraceListResponse>(`/api/traces${suffix}`);
  },
  fetchTraceDetail(traceId: string) {
    return request<TraceDetailResponse>(`/api/traces/${traceId}`);
  },
};
