var express = require("express");
var router = express.Router();
const auth = require("./api/auth");
const companies = require("./api/companies");
const companyUsers = require("./api/companyUsers");
const questions = require("./api/questions");
const media = require("./api/media");
const testResult = require("./api/testResult");
const guests = require("./api/guests");
const userResponses = require("./api/userResponses");
const authMiddleware = require("../middlewares/auth");
const domainMiddleware = require("../middlewares/checkCompany");
// const domainMiddleware = require("../middlewares/domainAuth");
const moment = require("moment");

/* GET home page. */
router.get("/", function (req, res, next) {
  res.render("index", { title: "ELD", host: req.headers.host });
});

router.get("/invitation", function (req, res, next) {
  // res.render("success", { title: "ELD" });
  res.send({ msg: "OK" });
});
router.get("/success", function (req, res, next) {
  res.render("success");
});

router.post("/api/admin/user/adminLogin", auth.adminLogin);
router.post("/api/admin/user/adminAccessToken", auth.adminAccessToken);

router.post("/api/user/login", auth.login);

//Company
router.post("/api/admin/company", companies.add);
router.get("/api/admin/company/all", companies.all);
router.get("/api/admin/company/getSingle/:id", companies.getSingle);
router.put("/api/admin/company/:id", companies.update);
router.delete("/api/admin/company/:id", companies.delete);
router.post("/api/admin/company/query", companies.query);
router.post("/api/admin/company/multipleDelete", companies.multipleDelete);
//Test Result
router.post("/api/testResult/add", authMiddleware, testResult.add);
router.get("/api/testResult/all", authMiddleware, testResult.all);
router.get(
  "/api/testResult/getSingle/:id",
  authMiddleware,
  testResult.getSingle
);
router.put("/api/testResult/:id", authMiddleware, testResult.update);
router.delete("/api/testResult/:id", authMiddleware, testResult.delete);
router.post("/api/testResult/query", authMiddleware, testResult.query);

//Company Users
router.post("/api/admin/companyUsers", companyUsers.add);
router.get("/api/admin/companyUsers/all", companyUsers.all);
router.get("/api/admin/companyUsers/getSingle/:id", companyUsers.getSingle);
router.put("/api/admin/companyUsers/:id", companyUsers.update);
router.delete("/api/admin/companyUsers/:id", companyUsers.delete);
router.post("/api/admin/companyUsers/query", companyUsers.query);
router.post(
  "/api/admin/companyUsers/changePassword",
  companyUsers.changePassword
);
router.post(
  "/api/admin/companyUsers/multipleDelete",
  companyUsers.multipleDelete
);

//Questions
router.post("/api/admin/question", questions.add);
router.get("/api/admin/question/all", questions.all);
router.get("/api/question/getSingle/:id", questions.getSingle);
router.get(
  "/api/question/getSingleFR/:id",
  domainMiddleware,
  questions.getSingleFR
);
router.put("/api/admin/question/:id", questions.update);
router.delete("/api/admin/question/:id", questions.delete);
router.post("/api/admin/question/query", questions.query);
router.post(
  "/api/admin/question/getCompanyQuestions",
  questions.getCompanyQuestions
);

router.post("/api/question/getFirstQuestion", questions.getFirstQuestion);
router.post(
  "/api/question/getFirstQuestionFR",
  domainMiddleware,
  questions.getFirstQuestionFR
);
router.post("/api/admin/question/markAsFirst", questions.markAsFirst);
router.post("/api/admin/question/multipleDelete", questions.multipleDelete);

//User Responses
router.post("/api/userResponses/add", authMiddleware, userResponses.add);
router.post("/api/userResponses/addFR", domainMiddleware, userResponses.addFR);
router.get("/api/userResponses/all", userResponses.all);
router.get("/api/userResponses/getSingle/:id", userResponses.getSingle);
router.put("/api/userResponses/:id", userResponses.update);
router.delete("/api/userResponses/:id", userResponses.delete);
router.post("/api/userResponses/query", userResponses.query);
router.post(
  "/api/userResponses/customerResponses",
  userResponses.customerResponses
);

//User Guests
router.post("/api/guests/add", authMiddleware, guests.add);
router.post("/api/guests/addFR", domainMiddleware, guests.addFR);
router.get("/api/guests/all", guests.all);
router.get("/api/guests/getSingle/:id", guests.getSingle);
router.put("/api/guests/:id", guests.update);
router.delete("/api/guests/:id", guests.delete);
router.post("/api/guests/query", guests.query);
router.post("/api/guests/delete", guests.delete);

//Media Image S3
router.post("/api/admin/media/getImageUploadUrl", media.getImageUploadUrl);

module.exports = router;
