import { Router } from 'express';
import { DealerController } from '../controllers/dealer.controller';
import { authenticateToken } from '../middlewares/auth.middleware';
import { asyncHandler } from '../middlewares/errorHandler.middleware';

const router = Router();
const dealerController = new DealerController();

/**
 * @route   GET /api/v1/dealers
 * @desc    Get all dealers
 * @access  Private
 */
router.get('/', authenticateToken, asyncHandler(dealerController.getAllDealers.bind(dealerController)));

/**
 * @route   GET /api/v1/dealers/search
 * @desc    Search dealers by name, code, or email
 * @access  Private
 */
router.get('/search', authenticateToken, asyncHandler(dealerController.searchDealers.bind(dealerController)));

/**
 * @route   GET /api/v1/dealers/code/:dealerCode
 * @desc    Get dealer by code
 * @access  Private
 */
router.get('/code/:dealerCode', authenticateToken, asyncHandler(dealerController.getDealerByCode.bind(dealerController)));

/**
 * @route   GET /api/v1/dealers/email/:email
 * @desc    Get dealer by email
 * @access  Private
 */
router.get('/email/:email', authenticateToken, asyncHandler(dealerController.getDealerByEmail.bind(dealerController)));

/**
 * @route   GET /api/v1/dealers/verify/:dealerCode
 * @desc    Verify dealer is logged in to the system
 * @access  Private
 */
router.get('/verify/:dealerCode', authenticateToken, asyncHandler(dealerController.verifyDealerLogin.bind(dealerController)));

export default router;

