const express = require('express');
const router = express.Router();
const db = require('../db');

// Get pincode details
router.get('/:pincode', async (req, res) => {
    const { pincode } = req.params;
    try {
        const result = await db.query('SELECT * FROM pincodes WHERE pincode = $1', [pincode]);
        if (result.rows.length === 0) {
            return res.status(404).json({ success: false, message: 'Pincode not found' });
        }
        res.json({ success: true, data: result.rows[0] });
    } catch (err) {
        console.error(err);
        res.status(500).json({ success: false, message: 'Server error fetching pincode' });
    }
});

module.exports = router;
