const express = require('express');
const router = express.Router();
const multer = require('multer');
const authorize = require('../../../../middlewares/authorize-sapps');
const drugCategoryService = require('./drugCategory.service');

router.post('/create', authorize(), create);
router.post('/', authorize(), getAll);
router.post('/option', authorize(), option);
router.get('/count', authorize(), count);
router.put('/:id', authorize(), update);
router.delete('/:id', authorize(), _delete);

module.exports = router;

/**
 * Create a new drugCategory
 * @param {Object} req.body - The drugCategory data
 * @param {Object} res - The response object
 * @param {Function} next - The next middleware function
 * @returns {Promise} - A promise resolving to the created drugCategory
 */
function create(req, res, next) {
    drugCategoryService.create(req.body)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Get a list of all drugCategorys
 * @param {Object} req.query - The query object
 * @param {Object} res - The response object
 * @param {Function} next - The next middleware function
 * @returns {Promise} - A promise resolving to an array of drugCategorys
 */
function getAll(req, res, next) {
    drugCategoryService.getAll(req.body)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Get an array of drugCategory objects to be used as options in a select box
 * @param {Object} req.query - The query object
 * @param {Object} res - The response object
 * @param {Function} next - The next middleware function
 * @returns {Promise} - A promise resolving to an array of drugCategory objects
 */
function option(req, res, next) {
    drugCategoryService.option(req.body)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Count the number of drugCategorys matching a query
 * @param {Object} req.query - The query object
 * @param {Object} res - The response object
 * @param {Function} next - The next middleware function
 * @returns {Promise} - A promise resolving to the count of drugCategorys
 */
function count(req, res, next) {
    drugCategoryService.count(req.query)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Update an existing drugCategory
 * @param {number} req.params.id - The drugCategory ID to be updated
 * @param {Object} req.body - The drugCategory data to be updated
 * @param {Object} res - The response object
 * @param {Function} next - The next middleware function
 * @returns {Promise} - A promise resolving to the updated drugCategory
 */
function update(req, res, next) {
    drugCategoryService.update(req.params.id, req.body)
        .then(result => res.json(result))
        .catch(next);
}

/**
 * Delete a drugCategory
 * @param {number} req.params.id - The drugCategory ID to be deleted
 * @param {Object} res - The response object
 * @param {Function} next - The next middleware function
 * @returns {Promise} - A promise resolving to the result of the deletion process
 */
function _delete(req, res, next) {
    drugCategoryService.delete(req.params.id)
        .then(result => res.json(result))
        .catch(next);
}
