import { FastifyInstance } from "fastify";
import { ZodTypeProvider } from "fastify-type-provider-zod";
import { z } from "zod";
import { prisma } from "../../../lib/prisma";

export async function getTotalActiveCourses(app: FastifyInstance) {
  app
    .withTypeProvider<ZodTypeProvider>()
    .get('/total-active-courses', {
      schema: {
        summary: 'Get total active courses',
        tags: ['courses'],
        response: {
          200: z.object({
            totalActiveCourses: z.number(),
          }),
        },
      },
    }, async (request, reply) => {
      const totalActiveCourses = await prisma.course.count({
        where: {
          status: true,
        },
      });

      return reply.send({
        totalActiveCourses,
      });
    });
}
