import { z } from "zod";
import { withV3ApiWrapper } from "@/app/api/v3/lib/api-wrapper";
import { ZV3EmptyQuery } from "@/app/api/v3/lib/schemas";
import { restoreV3Survey } from "../../lib/operations";

const surveyParamsSchema = z.object({
  surveyId: z.cuid2(),
});

export const POST = withV3ApiWrapper({
  auth: "both",
  action: "restored",
  targetType: "survey",
  schemas: {
    params: surveyParamsSchema,
    // Single-survey endpoints locate the survey by its globally-unique id; reject stray query params.
    query: ZV3EmptyQuery,
  },
  handler: async ({ parsedInput, authentication, requestId, instance, auditLog }) => {
    return await restoreV3Survey({
      surveyId: parsedInput.params.surveyId,
      authentication,
      requestId,
      instance,
      auditLog,
    });
  },
});
