import { registry } from "../../infrastructure/openapi/registry";
import { z } from "zod";
import { ErrorResponseSchema } from "../../infrastructure/openapi/security";
import { createServiceSchema, updateServiceSchema } from "./service.validation";
console.log("service.openapi loaded");
const ServiceResponseSchema = registry.register(
  "ServiceResponse",
  z.object({
    success: z.boolean().default(true),
    statusCode: z.number(),
    message: z.string(),
    data: z.any().optional(),
  }),
);

registry.registerPath({
  method: "post",
  path: "/services/create-service",
  summary: "Create a new service (Admin only)",
  tags: ["Services"],
  security: [{ bearerAuth: [] }],
  request: {
    body: {
      content: {
        "application/json": { schema: createServiceSchema.shape.body },
      },
    },
  },
  responses: {
    201: {
      description: "Service created",
      content: { "application/json": { schema: ServiceResponseSchema } },
    },
    400: {
      description: "Validation error",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
    403: {
      description: "Forbidden",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "get",
  path: "/services/get-all-services",
  summary: "Get all services of admin's organization",
  tags: ["Services"],
  security: [{ bearerAuth: [] }],
  responses: {
    200: {
      description: "Services fetched",
      content: { "application/json": { schema: ServiceResponseSchema } },
    },
    403: {
      description: "Forbidden",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "get",
  path: "/services/{serviceId}",
  summary: "Get a single service by ID",
  tags: ["Services"],
  security: [{ bearerAuth: [] }],
  request: { params: z.object({ serviceId: z.string() }) },
  responses: {
    200: {
      description: "Service fetched",
      content: { "application/json": { schema: ServiceResponseSchema } },
    },
    404: {
      description: "Not found",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "put",
  path: "/services/{serviceId}",
  summary: "Update a service (Admin only)",
  tags: ["Services"],
  security: [{ bearerAuth: [] }],
  request: {
    params: z.object({ serviceId: z.string() }),
    body: {
      content: {
        "application/json": { schema: updateServiceSchema.shape.body },
      },
    },
  },
  responses: {
    200: {
      description: "Service updated",
      content: { "application/json": { schema: ServiceResponseSchema } },
    },
    404: {
      description: "Not found",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "delete",
  path: "/services/{serviceId}",
  summary: "Delete a service (Admin only)",
  tags: ["Services"],
  security: [{ bearerAuth: [] }],
  request: { params: z.object({ serviceId: z.string() }) },
  responses: {
    200: {
      description: "Service deleted",
      content: { "application/json": { schema: ServiceResponseSchema } },
    },
    404: {
      description: "Not found",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});
