import * as express from 'express';
import { Request, Response } from 'express';
import { authentification } from '../../../middlewares/authentication.middleware';
import { authorization } from '../../../middlewares/authorization.middleware';
import { Roles } from '../../auth/enums/roles.enum';
import { PaymentLinkController } from '../controllers/payment-link.controller';

const Router = express.Router();
const staffRoles = [Roles.ADMIN, Roles.RECEPTIONIST];

Router.get('/', (req: Request, res: Response) => {
  void PaymentLinkController.listPublic(req, res);
});

Router.get(
  '/admin',
  authentification,
  authorization(staffRoles),
  (req: Request, res: Response) => { void PaymentLinkController.listAdmin(req, res); }
);

Router.post(
  '/',
  authentification,
  authorization([Roles.ADMIN]),
  (req: Request, res: Response) => { void PaymentLinkController.create(req, res); }
);

Router.get(
  '/appointment/:appointmentId',
  authentification,
  authorization(staffRoles),
  (req: Request, res: Response) => { void PaymentLinkController.getForAppointment(req, res); }
);

Router.post(
  '/generate',
  authentification,
  authorization(staffRoles),
  (req: Request, res: Response) => { void PaymentLinkController.generateForAppointment(req, res); }
);

Router.post(
  '/verify',
  authentification,
  authorization(staffRoles),
  (req: Request, res: Response) => { void PaymentLinkController.verify(req, res); }
);

Router.patch(
  '/:id',
  authentification,
  authorization([Roles.ADMIN]),
  (req: Request, res: Response) => { void PaymentLinkController.update(req, res); }
);

Router.delete(
  '/:id',
  authentification,
  authorization([Roles.ADMIN]),
  (req: Request, res: Response) => { void PaymentLinkController.remove(req, res); }
);

export default Router;
