import { FastifyInstance } from 'fastify';
import { listCategories, createCategory } from '../services/recipe.service.js';

export async function categoryRoutes(app: FastifyInstance) {
  app.get('/api/categories', async () => {
    return await listCategories();
  });

  app.post('/api/categories', async (request, reply) => {
    const { name } = request.body as { name: string };
    if (!name) return reply.status(400).send({ error: 'name required' });
    const cat = await createCategory(name);
    return reply.status(201).send(cat);
  });
}
