import { registry } from "../../infrastructure/openapi/registry";
import { z } from "zod";
import { ErrorResponseSchema } from "../../infrastructure/openapi/security";

const DocResponseSchema = registry.register(
  "ServiceDocumentResponse",
  z.object({
    success: z.boolean(),
    statusCode: z.number(),
    message: z.string(),
    data: z.any(),
  }),
);

registry.registerPath({
  method: "get",
  path: "/services/{serviceId}/documents",
  summary: "Get all documents for a service",
  tags: ["Service Documents"],
  security: [{ bearerAuth: [] }],
  request: { params: z.object({ serviceId: z.string() }) },
  responses: {
    200: {
      description: "Documents fetched",
      content: { "application/json": { schema: DocResponseSchema } },
    },
    404: {
      description: "Not found",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "post",
  path: "/services/{serviceId}/documents",
  summary: "Bulk create/update documents for a service",
  tags: ["Service Documents"],
  security: [{ bearerAuth: [] }],
  request: {
    params: z.object({ serviceId: z.string() }),
    body: {
      content: {
        "application/json": {
          schema: z.object({
            documents: z.array(
              z.object({
                id: z.string().optional(),
                name: z.string(),
                isRequired: z.boolean().optional(),
              }),
            ),
          }),
        },
      },
    },
  },
  responses: {
    200: {
      description: "Documents saved",
      content: { "application/json": { schema: DocResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "delete",
  path: "/services/{serviceId}/documents/{documentId}",
  summary: "Delete a service document",
  tags: ["Service Documents"],
  security: [{ bearerAuth: [] }],
  request: {
    params: z.object({ serviceId: z.string(), documentId: z.string() }),
  },
  responses: {
    200: {
      description: "Document deleted",
      content: { "application/json": { schema: DocResponseSchema } },
    },
    404: {
      description: "Not found",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});
