import { Router } from 'express';

import requiredParameters from '../middlewares/requiredParameters.js';
import existance from '../middlewares/existance.js';
import auth from '../middlewares/auth.js';

import utils from '../utils.js';
import UserController from '../controllers/user.js';
import ApiController from '../controllers/api.js';

const ApiRouter = new Router();

ApiRouter.post('/register', requiredParameters.requireUsername, requiredParameters.requirePassword, auth.validateInviteToken, existance.userDoesNotExist, UserController.register);
ApiRouter.post('/login', requiredParameters.requireUsername, requiredParameters.requirePassword, existance.userExist, UserController.login);
ApiRouter.get('/logout', auth.authenticate, UserController.logout);
ApiRouter.post('/changepassword', auth.authenticate, existance.userExist, UserController.changePassword);

ApiRouter.post('/uploadSkin', existance.userExist, auth.authenticate, utils.upload.single('file'), requiredParameters.requireFile, UserController.uploadSkin);
ApiRouter.post('/uploadCape', existance.userExist, auth.authenticate, auth.canHaveCloak, utils.upload.single('file'), requiredParameters.requireFile, UserController.uploadCape);

ApiRouter.get('/getUsername', existance.userExist, auth.authenticate, UserController.getUsername);
ApiRouter.get('/getChatMessages/:offset/:limit', auth.authenticate, ApiController.getChatMessages);
ApiRouter.get('/webSocketConnection', auth.authenticate, ApiController.getWebsocketConnection);

ApiRouter.get('/skinsUrl', auth.authenticate, ApiController.getSkinsUrl);
ApiRouter.get('/capesUrl', auth.authenticate, ApiController.getCapesUrl);

export default ApiRouter;
