const express = require("express");
const router = express.Router();
const authorize = require("../../../../middlewares/authorize-sapps");
const budgetPlanService = require("./budgetPlan.service");

router.post("/create", authorize(), create);
router.post("/", authorize(), getAll);
router.post("/option", authorize(), option);
router.post("/count", authorize(), count);
router.put("/:id", authorize(), update);
router.put("/update-budgetplanitem/:id", authorize(), updateBudgetPlanItem);
router.put("/enabled/:id", authorize(), enabled);
router.delete("/:id", authorize(), _delete);

module.exports = router;

function create(req, res, next) {
	budgetPlanService
		.create(req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function getAll(req, res, next) {
	budgetPlanService
		.getAll(req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function option(req, res, next) {
	budgetPlanService
		.option(req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function count(req, res, next) {
	budgetPlanService
		.count(req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function update(req, res, next) {
	budgetPlanService
		.update(req.params.id, req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function updateBudgetPlanItem(req, res, next) {
	budgetPlanService
		.updateBudgetPlanItem(req.params.id, req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function enabled(req, res, next) {
	budgetPlanService
		.enabled(req.params.id, req.body)
		.then((result) => res.json(result))
		.catch(next);
}

function _delete(req, res, next) {
	budgetPlanService
		.delete(req.params.id)
		.then((result) => res.json(result))
		.catch(next);
}
