const express = require('express');
const router = express.Router();
const { login, googleToken, googleAuth, googleCallback, googleCallbackJSON } = require('../controllers/loginController');

// POST /login - Traditional email/password login
router.post('/login', (req, res, next) => {
  console.log('[LOGIN ROUTE] POST /login hit');
  login(req, res, next);
});

// POST /auth/google/token - Verify Google ID token (from frontend @react-oauth/google) and return app JWT
router.post('/auth/google/token', googleToken);

// GET /auth/google - Initiate Google OAuth
router.get('/auth/google', googleAuth);

// GET /auth/google/callback - Google OAuth callback (redirects to frontend)
router.get('/auth/google/callback', googleCallback);

// GET /auth/google/callback/json - Google OAuth callback (returns JSON)
router.get('/auth/google/callback/json', googleCallbackJSON);

module.exports = router;