import { FastifyInstance } from "fastify";
import { ZodTypeProvider } from "fastify-type-provider-zod";
import { z } from "zod";
import { prisma } from "../../../lib/prisma";

export async function getTotalCustomers(app: FastifyInstance) {
  app
    .withTypeProvider<ZodTypeProvider>()
    .get('/total-customers', {
      schema: {
        summary: 'Get total customers',
        tags: ['users'],
        response: {
          200: z.object({
            totalCustomers: z.number(),
          }),
        },
      },
    }, async (request, reply) => {
      const totalCustomers = await prisma.user.count({
        where: {
          role: 'customer',
        },
      });

      return reply.send({
        totalCustomers,
      });
    });
}
