import express from 'express';
import { auth } from '../../middleware/auth';
import { searchArticles } from './controllers/search';
import { sitemapArticles } from './controllers/sitemap';
import { listArticles } from './controllers/list';
import {
  getArticle,
  createArticle,
  updateArticle,
  deleteArticle,
  importArticles,
  activeArticle,
  reactArticle
} from './controllers/crud';

const router = express.Router();

// Поиск и список routes
router.get('/search', searchArticles);
router.get('/sitemap', sitemapArticles);
router.get('/', listArticles);

// Импорт route
// Настройка middleware для обработки JSON
router.use(express.json({ limit: '10mb' }));
router.post('/import', auth, importArticles);

// CRUD routes
router.get('/:id', getArticle);
router.post('/', auth, createArticle);
router.put('/:id', auth, updateArticle);
router.put('/active/:id', auth, activeArticle);
router.put('/react/:id', reactArticle);
router.delete('/:id', auth, deleteArticle);

export default router;