/**
 * Workplace Routes
 */

const express = require('express');
const router = express.Router();
const workplaceController = require('../controllers/workplaceController');
const { requireAuth, requireAdminOrPermission } = require('../middleware/auth');
const upload = require('../middleware/upload');

const wpPerm = requireAdminOrPermission('tkuser.workplaces');

router.get('/categories', requireAuth, workplaceController.getCategories);

// 구역지도 (/:id 보다 먼저 등록)
router.post('/categories/:id/layout-image', wpPerm, upload.single('image'), workplaceController.uploadCategoryLayoutImage);
router.get('/categories/:categoryId/map-regions', requireAuth, workplaceController.getMapRegionsByCategory);
router.post('/map-regions', wpPerm, workplaceController.createMapRegion);
router.put('/map-regions/:id', wpPerm, workplaceController.updateMapRegion);
router.delete('/map-regions/:id', wpPerm, workplaceController.deleteMapRegion);

router.post('/:id/layout-image', wpPerm, upload.single('image'), workplaceController.uploadWorkplaceLayoutImage);

router.get('/', requireAuth, workplaceController.getAll);
router.get('/:id', requireAuth, workplaceController.getById);
router.post('/', wpPerm, workplaceController.create);
router.put('/:id', wpPerm, workplaceController.update);
router.delete('/:id', wpPerm, workplaceController.remove);

module.exports = router;
