import fp from 'fastify-plugin';
import { z } from 'zod/v4';
import type { ZodTypeProvider } from 'fastify-type-provider-zod';

const packageVersion = '0.0.1';

export default fp(
  async (fastify) => {
    const app = fastify.withTypeProvider<ZodTypeProvider>();

    app.route({
      method: 'GET',
      url: '/api/v1/health',
      config: { public: true },
      schema: {
        response: {
          200: z.object({
            status: z.literal('ok'),
            version: z.string(),
            uptime: z.number(),
          }),
        },
      },
      handler: async (_request, reply) => {
        return reply.send({
          status: 'ok' as const,
          version: packageVersion,
          uptime: process.uptime(),
        });
      },
    });
  },
  { name: 'health-routes' },
);
