import express from 'express';
import { AuthController } from '../controllers/auth.controller';
import { validate } from '../middleware/validate';
import { authenticateToken } from '../middleware/auth';
import { loginSchema, registerSchema, changePasswordSchema, updateProfileSchema } from '../schemas/auth';

const router = express.Router();

// Public routes
router.post('/login', validate(loginSchema), AuthController.login);
router.post('/register', validate(registerSchema), AuthController.register);

// Protected routes
router.use(authenticateToken); // Standard middleware now

router.get('/me', AuthController.getCurrentUser);
router.post('/change-password', validate(changePasswordSchema), AuthController.changePassword);
router.patch('/profile', validate(updateProfileSchema), AuthController.updateProfile);
router.post('/initialize', AuthController.initializeAccount);

// Admin routes
router.get('/users', AuthController.getAllUsers);
router.delete('/users/:id', AuthController.deleteUser);
router.patch('/users/:id/block', AuthController.toggleBlockUser);
router.post('/users/:id/reset-password', AuthController.resetUserPassword);

export default router;
