import express from 'express';
import multer from 'multer';
import { authenticate } from '../middleware/authMiddleware.js';
import {
  uploadTournamentPdf,
  getParsedTournament,
  listOfficialTournaments,
  deleteOfficialTournament,
  updateOfficialTournament,
  upsertCompetitionMember,
  listClubParticipations,
  updateParticipantStatus,
  autoRegisterOfficialTournamentParticipants
} from '../controllers/officialTournamentController.js';

const router = express.Router();
const upload = multer({ storage: multer.memoryStorage() });

router.use(authenticate);

router.get('/:clubId', listOfficialTournaments);
router.get('/:clubId/participations/summary', listClubParticipations);
router.post('/:clubId/upload', upload.single('pdf'), uploadTournamentPdf);
router.get('/:clubId/:id', getParsedTournament);
router.patch('/:clubId/:id', updateOfficialTournament);
router.delete('/:clubId/:id', deleteOfficialTournament);
router.post('/:clubId/:id/participation', upsertCompetitionMember);
router.post('/:clubId/:id/status', updateParticipantStatus);
router.post('/:clubId/:id/auto-register', autoRegisterOfficialTournamentParticipants);

export default router;

