import { registry } from "../../infrastructure/openapi/registry";
import { z } from "zod";
import { ErrorResponseSchema } from "../../infrastructure/openapi/security";

const PaymentResponseSchema = registry.register(
  "PaymentResponse",
  z.object({
    success: z.boolean().default(true),
    statusCode: z.number().default(200),
    message: z.string().optional(),
    data: z.any().optional(),
  }),
);

registry.registerPath({
  method: "post",
  path: "/payments/stripe/checkout/{invoiceId}",
  summary: "Create a Stripe checkout session for an invoice (Client only)",
  tags: ["Payments"],
  security: [{ bearerAuth: [] }],
  request: {
    params: z.object({ invoiceId: z.string().describe("Invoice ID") }),
  },
  responses: {
    200: {
      description: "Stripe checkout session created successfully",
      content: { "application/json": { schema: PaymentResponseSchema } },
    },
    400: {
      description:
        "Invalid invoice amount, invoice already paid/cancelled, or unable to create checkout session",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
    401: {
      description: "Unauthorized",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
    404: {
      description: "Client or invoice not found",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});

registry.registerPath({
  method: "get",
  path: "/payments/client/invoices/{invoiceId}",
  summary: "Get invoice details with payment link (Client only)",
  tags: ["Payments"],
  security: [{ bearerAuth: [] }],
  request: {
    params: z.object({ invoiceId: z.string().describe("Invoice ID") }),
  },
  responses: {
    200: {
      description: "Invoice fetched successfully",
      content: { "application/json": { schema: PaymentResponseSchema } },
    },
    401: {
      description: "Unauthorized",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
    404: {
      description: "Client or invoice not found",
      content: { "application/json": { schema: ErrorResponseSchema } },
    },
  },
});
