const express = require('express');
const router = express.Router();
const symbolController = require('../controllers/symbolController');
const { validate, validateQuery, validateParams, symbolSchema, symbolIdSchema } = require('../middleware/validation');

// GET /api/symbols - Get all symbols with optional filtering
router.get('/', validateQuery(require('joi').object({
  exchange: require('joi').string().max(50),
  instrumentType: require('joi').string().valid('crypto', 'stock', 'forex', 'commodity'),
  isActive: require('joi').string().valid('true', 'false'),
  limit: require('joi').number().integer().min(1).max(1000).default(100),
  offset: require('joi').number().integer().min(0).default(0)
})), symbolController.getAllSymbols);

// GET /api/symbols/search - Search symbols by name
router.get('/search', validateQuery(require('joi').object({
  q: require('joi').string().required(),
  limit: require('joi').number().integer().min(1).max(100).default(20)
})), symbolController.searchSymbols);

// GET /api/symbols/:id - Get symbol by ID
router.get('/:id', validateParams(symbolIdSchema), symbolController.getSymbolById);

// POST /api/symbols - Create new symbol
router.post('/', validate(symbolSchema), symbolController.createSymbol);

// PUT /api/symbols/:id - Update symbol
router.put('/:id', validateParams(symbolIdSchema), validate(symbolSchema), symbolController.updateSymbol);

// DELETE /api/symbols/:id - Delete symbol (soft delete)
router.delete('/:id', validateParams(symbolIdSchema), symbolController.deleteSymbol);

module.exports = router;
