const express = require('express')
const router = express.Router()
const LocationController = require('../controllers/locationController')
const { authenticateToken, authorizePermission } = require('../middleware/auth')
const validation = require('../middleware/locationValidation')

router.use(authenticateToken)

// Countries
router.get('/countries', LocationController.getCountries)
router.get('/countries/:id', LocationController.getCountryById)
router.post('/countries', validation.createCountryValidation, LocationController.createCountry)
router.put('/countries/:id', validation.updateCountryValidation, LocationController.updateCountry)
router.delete('/countries/:id', LocationController.deleteCountry)

// Divisions
router.get('/divisions', LocationController.getDivisions)
router.get('/divisions/country/:country_id', LocationController.getDivisionsByCountry)
router.get('/divisions/:id', LocationController.getDivisionById)
router.post('/divisions', validation.createDivisionValidation, LocationController.createDivision)
router.put('/divisions/:id', validation.updateDivisionValidation, LocationController.updateDivision)
router.delete('/divisions/:id', LocationController.deleteDivision)

// Districts
router.get('/districts', LocationController.getDistricts)
router.get('/districts/division/:division_id', LocationController.getDistrictsByDivision)
router.get('/districts/:id', LocationController.getDistrictById)
router.post('/districts', authorizePermission('district.create'), validation.createDistrictValidation, LocationController.createDistrict)
router.put('/districts/:id', authorizePermission('district.update'), validation.updateDistrictValidation, LocationController.updateDistrict)
router.delete('/districts/:id', authorizePermission('district.delete'), LocationController.deleteDistrict)

// Thanas
router.get('/thanas', LocationController.getThanas)
router.get('/thanas/district/:district_id', LocationController.getThanasByDistrict)
router.get('/thanas/:id', LocationController.getThanaById)
router.post('/thanas', authorizePermission('thana.create'), validation.createThanaValidation, LocationController.createThana)
router.put('/thanas/:id', authorizePermission('thana.update'), validation.updateThanaValidation, LocationController.updateThana)
router.delete('/thanas/:id', authorizePermission('thana.delete'), LocationController.deleteThana)

module.exports = router
