// src/routes/personalization.routes.ts
import { Router, Request, Response, NextFunction } from 'express';
import { z } from 'zod';
import * as db from '../services/db/index.db';
import { validateRequest } from '../middleware/validation.middleware';

const router = Router();

// --- Zod Schemas for Personalization Routes (as per ADR-003) ---
// These routes do not expect any input, so we define an empty schema
// to maintain a consistent validation pattern across the application.
const emptySchema = z.object({});

/**
 * GET /api/personalization/master-items - Get the master list of all grocery items.
 */
router.get('/master-items', validateRequest(emptySchema), async (req: Request, res: Response, next: NextFunction) => {
    try {
        const masterItems = await db.personalizationRepo.getAllMasterItems(req.log);
        res.json(masterItems);
    } catch (error) {
        req.log.error({ error }, 'Error fetching master items in /api/personalization/master-items:');
        next(error);
    }
});

/**
 * GET /api/personalization/dietary-restrictions - Get the master list of all dietary restrictions.
 */
router.get('/dietary-restrictions', validateRequest(emptySchema), async (req: Request, res: Response, next: NextFunction) => {
    try {
        const restrictions = await db.personalizationRepo.getDietaryRestrictions(req.log);
        res.json(restrictions);
    } catch (error) {
        req.log.error({ error }, 'Error fetching dietary restrictions in /api/personalization/dietary-restrictions:');
        next(error);
    }
});

/**
 * GET /api/personalization/appliances - Get the master list of all kitchen appliances.
 */
router.get('/appliances', validateRequest(emptySchema), async (req: Request, res: Response, next: NextFunction) => {
    try {
        const appliances = await db.personalizationRepo.getAppliances(req.log);
        res.json(appliances);
    } catch (error) {
        req.log.error({ error }, 'Error fetching appliances in /api/personalization/appliances:');
        next(error);
    }
});

export default router;