import { apiFetch } from "./http";
import type { OperationLogListResponse, OperationLogQuery } from "./types";

export function listOperationLogs(query: OperationLogQuery = {}): Promise<OperationLogListResponse> {
  const params = new URLSearchParams();

  Object.entries(query).forEach(([key, value]) => {
    if (value !== undefined && value !== null && String(value).trim() !== "") {
      params.set(key, String(value));
    }
  });

  const search = params.toString();
  return apiFetch<OperationLogListResponse>(`/api/operation-logs${search ? `?${search}` : ""}`);
}
