const express = require("express");
const router = express.Router();

const ctrlUser = require("../controllers/user.controller");

const ctrlfeedBack = require("../controllers/feedBack.controller");

const ctrlartfeedBack = require("../controllers/articleFeedback.controller");

const ctrlfeedbackEntries = require("../controllers/feedbackEntries.controller");

const ctrlclickEntries = require("../controllers/clickEntries.controller");

const ctrlqueryHistory = require("../controllers/queryHistory.controller");

const ctrlarticleInfos = require("../controllers/articleInfos.controller");

const ctrlqueryInfos = require("../controllers/queryInfos.controller");
//const test = require("../controllers/test.controller");

const jwtHelper = require("../config/jwtHelper");

/**
 * These will be called depending on which function is called from the user.service.ts
 */
router.post("/search", ctrlUser.search);
router.post("/register", ctrlUser.register);
router.post("/authenticate", ctrlUser.authenticate);
router.post("/mergeByKey", ctrlUser.mergeByKey);
//returns an object with a formatted date using toLocaleString()
router.post("/getObjectDate", ctrlUser.getObjectDate);
router.post("/getArticle",  ctrlUser.getArticle);
router.get("/userProfile", jwtHelper.verifyJwtToken, ctrlUser.userProfile);
router.post("/updateProfile", jwtHelper.verifyJwtToken,ctrlUser.updateProfile);
router.post("/savearticle", jwtHelper.verifyJwtToken, ctrlUser.saveArticle);
router.post("/unsavearticle", jwtHelper.verifyJwtToken, ctrlUser.unsaveArticle);
router.post("/savesearch", jwtHelper.verifyJwtToken, ctrlUser.saveSearch);
router.post("/saveclick", jwtHelper.verifyJwtToken, ctrlUser.saveClick);
router.post("/question", ctrlfeedBack.question);
/*newly added : article feedback*/
router.post("/rating", ctrlartfeedBack.rating);
router.post("/getRating", ctrlartfeedBack.getRating);
router.get("/articleRatings", ctrlartfeedBack.articleRatings);
router.post("/savefeedback",jwtHelper.verifyJwtToken, ctrlUser.saveFeedback);
router.post("/updateAccountType",ctrlUser.updateAccountType);
/*newly added : feedback entries*/

router.post("/saveQueries",ctrlqueryHistory.saveQueries);
router.post("/globalQuerySearches", ctrlqueryHistory.globalQuerySearches);
router.get('/countQuerySearches', ctrlqueryHistory.countQuerySearches);
router.post("/saveEntries",ctrlfeedbackEntries.saveEntries);
router.get("/feedbackInteractions", ctrlfeedbackEntries.feedbackInteractions);
router.post("/saveClicks",ctrlclickEntries.saveClicks);
router.get("/articleClicks",ctrlclickEntries.articleClicks);

/* new methods for updating global information in queryInfos collection */
router.post("/updateQuerySearches",ctrlqueryInfos.updateQuerySearches);
router.post("/updateQueryArticleClicks",ctrlqueryInfos.updateQueryArticleClicks);
router.post("/updateQueryArticleFeedbacks",ctrlqueryInfos.updateQueryArticleFeedbacks);
/* new methods for accessing information in queryInfos collection */
router.post("/globalProperties",ctrlqueryInfos.getGlobalProperties);

/* new methods for updating global information in queryInfos collection */
router.post("/updateArticleInfoClicks", ctrlarticleInfos.updateArticleInfoClicks);
router.post("/updateArticleInfoRating", ctrlarticleInfos.updateArticleInfoRating);
/* new methods for updating global information in queryInfos collection */
router.post("/getArticleInfoProperties", ctrlarticleInfos.getArticleInfoProperties);


module.exports = router;
