import { Router } from 'express';
import { UserController } from '../controllers/user.controller';
import { authenticateToken } from '../middlewares/auth.middleware';
import { asyncHandler } from '../middlewares/errorHandler.middleware';
import { getPublicConfigurations } from '../controllers/admin.controller';

const router = Router();
const userController = new UserController();

// GET /api/v1/users - Get all users
router.get('/', authenticateToken, asyncHandler(userController.getAllUsers.bind(userController)));

// GET /api/v1/users/search?q=<email or name>
router.get('/search', authenticateToken, asyncHandler(userController.searchUsers.bind(userController)));

// GET /api/v1/users/search-by-displayname?displayName=John Doe
router.get('/search-by-displayname', authenticateToken, asyncHandler(userController.searchByDisplayName.bind(userController)));

// GET /api/v1/users/configurations - Get public configurations (document policy, workflow sharing, TAT settings)
router.get('/configurations', authenticateToken, asyncHandler(getPublicConfigurations));

// POST /api/v1/users/ensure - Ensure user exists in DB (create if not exists)
router.post('/ensure', authenticateToken, asyncHandler(userController.ensureUserExists.bind(userController)));

// GET /api/v1/users/:userId - Get user by ID
router.get('/:userId', authenticateToken, asyncHandler(userController.getUserById.bind(userController)));

export default router;


