import { Router } from 'express';
import {
  register,
  login,
  googleAuth,
  verifyEmail,
  resendOtp,
  forgotPassword,
  resetPassword,
  updateProfile,
  changePassword,
  requestEmailChange,
  verifyEmailChange,
  me,
  logout,
} from '../controllers/auth.controller.js';
import { authenticate } from '../middleware/auth.middleware.js';
import { verifyRecaptcha } from '../middleware/recaptcha.middleware.js';

const router = Router();

router.post('/register', verifyRecaptcha, register);
router.post('/login', verifyRecaptcha, login);
router.post('/google', googleAuth);
router.post('/verify-email', verifyEmail);
router.post('/resend-otp', resendOtp);
router.post('/forgot-password', forgotPassword);
router.post('/reset-password', resetPassword);
router.post('/logout', logout);
router.get('/me', authenticate, me);

// Self-service account management (logged-in user)
router.patch('/profile', authenticate, updateProfile);
router.post('/change-password', authenticate, changePassword);
router.post('/change-email', authenticate, requestEmailChange);
router.post('/change-email/verify', authenticate, verifyEmailChange);

export default router;
