/**
 * MSW handlers for filter detail, filter params, dependents,
 * rename, and deletion endpoints.
 * @module mocks/handlers/operations
 */
import { http, HttpResponse } from "msw";
import { captureRequest } from "../request-log.js";

export const operationsHandlers = [
  // Filter detail
  http.get("/api/filters/:id", ({ params }) => {
    captureRequest("GET", `/api/filters/${params.id}`);
    return HttpResponse.json({
      rules: [],
      log: { id: 1 },
      name: "filtered-sample",
    });
  }),

  // Filter params and has-result
  http.get("/api/filters/params*", ({ request }) => {
    captureRequest("GET", new URL(request.url).pathname);
    return HttpResponse.json({});
  }),

  http.get("/api/filters/has-result*", ({ request }) => {
    captureRequest("GET", new URL(request.url).pathname);
    return HttpResponse.json(false);
  }),

  // Dependents
  http.get("/api/logs/:id/dependents", ({ params }) => {
    captureRequest("GET", `/api/logs/${params.id}/dependents`);
    return HttpResponse.json([]);
  }),

  http.get("/api/filters/:id/dependents", ({ params }) => {
    captureRequest("GET", `/api/filters/${params.id}/dependents`);
    return HttpResponse.json([]);
  }),

  http.get("/api/log-checks/:id/dependents", ({ params }) => {
    captureRequest("GET", `/api/log-checks/${params.id}/dependents`);
    return HttpResponse.json([]);
  }),

  http.get("/api/filter-checks/:id/dependents", ({ params }) => {
    captureRequest("GET", `/api/filter-checks/${params.id}/dependents`);
    return HttpResponse.json([]);
  }),

  // Rename
  http.put("/api/logs/:id/rename", async ({ request, params }) => {
    const body = await request.json();
    captureRequest("PUT", `/api/logs/${params.id}/rename`, body);
    return HttpResponse.json({ success: true });
  }),

  http.put("/api/filters/:id/rename", async ({ request, params }) => {
    const body = await request.json();
    captureRequest("PUT", `/api/filters/${params.id}/rename`, body);
    return HttpResponse.json({ success: true });
  }),

  // Deletion
  http.delete("/api/deletion/:id", ({ params }) => {
    captureRequest("DELETE", `/api/deletion/${params.id}`);
    return HttpResponse.json({ success: true });
  }),
];
