import { Router } from 'express';
import { query } from '../db.js';
import { requireAuth } from '../middleware/auth.js';

const router = Router();

router.post('/:id/score', requireAuth, async (req, res) => {
  const { id } = req.params;
  const { score_a, score_b } = req.body || {};
  if(score_a==null || score_b==null) return res.status(400).json({error:'score_a and score_b required'});
  await query(`UPDATE matches SET score_a=$1, score_b=$2, finished=TRUE WHERE id=$3`, [score_a, score_b, id]);
  res.json({ ok: true });
});

export default router;
