import { Router, type IRouter } from 'express';
import { authenticate } from '../middlewares/auth.middleware.js';
import * as trialInvitationsController from '../controllers/trial-invitations.controller.js';

const router: IRouter = Router();

// Public endpoint: anyone can view invitation details by token (no auth required)
router.get('/token/:token', trialInvitationsController.getInvitationByToken);

// Authenticated endpoints
router.use(authenticate);

// Global admin endpoints
router.post('/', trialInvitationsController.createInvitation);
router.get('/', trialInvitationsController.getAllInvitations);
router.post('/:id/cancel', trialInvitationsController.cancelInvitation);

// Self-serve endpoints (autenticado, owner validation in controller)
router.get('/pending', trialInvitationsController.getMyPendingInvitation);
router.post('/:token/accept', trialInvitationsController.acceptInvitation);

export { router as trialInvitationRoutes };
