const express = require('express');
const router = express.Router();
const multer = require('multer');
const path = require('path');

const factoryInfoController = require('../controllers/factoryInfoController');
const { verifyToken } = require('../middlewares/authMiddleware');  // ← 수정
const { requireAccess } = require('../middlewares/accessMiddleware');  // ← 수정

// 📦 파일 저장 설정
const storage = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, 'public/uploads/');
  },
  filename: (req, file, cb) => {
    const uniqueName = `map_image-${Date.now()}${path.extname(file.originalname)}`;
    cb(null, uniqueName);
  }
});
const upload = multer({ storage });

// CREATE
router.post(
  '/',
  verifyToken,  // ← 수정
  upload.single('map_image'),
  factoryInfoController.createFactoryInfo
);

// READ ALL
router.get('/', verifyToken, factoryInfoController.getAllFactoryInfo);  // ← 수정

// READ ONE
router.get('/:factory_id', verifyToken, factoryInfoController.getFactoryInfoById);  // ← 수정

// UPDATE
router.put('/:factory_id', verifyToken, factoryInfoController.updateFactoryInfo);  // ← 수정

// DELETE
router.delete('/:factory_id', verifyToken, factoryInfoController.removeFactoryInfo);  // ← 수정

module.exports = router;