import { FastifyInstance } from 'fastify';
import * as svc from '../services/tag.service.js';

export async function tagRoutes(app: FastifyInstance) {
  app.get('/api/tags', async () => {
    return await svc.listTags();
  });

  app.get('/api/tags/:name/recipes', async (request, reply) => {
    const { name } = request.params as { name: string };
    const result = await svc.getRecipesByTag(name);
    if (!result) return reply.status(404).send({ error: 'Tag not found' });
    return result;
  });
}
