import { Router } from 'express'
import { authenticate, authorize } from '@/shared/middleware/auth'
import { categoriesController } from './categories.controller'

const router = Router()

// All routes require authentication
router.use(authenticate)

// ========== CATEGORIES ==========

// Get all categories (flat list)
router.get(
  '/',
  authorize('contacts', 'all', 'read'),
  categoriesController.findAll.bind(categoriesController)
)

// Get category tree (hierarchical)
router.get(
  '/tree',
  authorize('contacts', 'all', 'read'),
  categoriesController.getTree.bind(categoriesController)
)

// Get category by ID
router.get(
  '/:id',
  authorize('contacts', 'all', 'read'),
  categoriesController.findById.bind(categoriesController)
)

// Create category
router.post(
  '/',
  authorize('contacts', 'all', 'create'),
  categoriesController.create.bind(categoriesController)
)

// Update category
router.put(
  '/:id',
  authorize('contacts', 'all', 'update'),
  categoriesController.update.bind(categoriesController)
)

// Delete category
router.delete(
  '/:id',
  authorize('contacts', 'all', 'delete'),
  categoriesController.delete.bind(categoriesController)
)

export default router
