const express = require('express');
const router = express.Router();
const blogController = require('../controllers/blogController');
const { protect: authenticateToken, admin: isAdmin } = require('../middleware/authMiddleware');

// Public Routes
router.get('/', blogController.getPosts);
router.get('/post/:slug', blogController.getPostBySlug);

const upload = require('../middleware/uploadMiddleware');

// Admin Routes
router.post('/generate-seo', authenticateToken, isAdmin, blogController.generateSeo);
router.post('/generate-title', authenticateToken, isAdmin, blogController.generateTitle);
router.post('/enhance-content', authenticateToken, isAdmin, blogController.enhanceContent);
router.post('/upload', authenticateToken, isAdmin, upload.single('image'), blogController.uploadImage);
router.post('/import', authenticateToken, isAdmin, blogController.importPosts);
router.get('/admin/all', authenticateToken, isAdmin, blogController.getAllPostsAdmin);
// Automation Routes
router.get('/automation/status', authenticateToken, isAdmin, blogController.getAutomationStatus);
router.post('/automation/trigger', authenticateToken, isAdmin, blogController.triggerAutomation); // Auto mode
router.get('/automation/trending', authenticateToken, isAdmin, blogController.getTrendingTitles); // Fetch trends
router.post('/automation/create-from-title', authenticateToken, isAdmin, blogController.createPostFromTitle); // Manual select
router.post('/automation/create-custom', authenticateToken, isAdmin, blogController.createPostCustom); // Custom topic
router.get('/automation/settings', authenticateToken, isAdmin, blogController.getAutomationSettings);
router.put('/automation/settings', authenticateToken, isAdmin, blogController.updateAutomationSettings);
router.get('/:id', authenticateToken, isAdmin, blogController.getPostById);
router.post('/', authenticateToken, isAdmin, blogController.createPost);
router.put('/:id', authenticateToken, isAdmin, blogController.updatePost);
router.get('/categories', authenticateToken, isAdmin, blogController.getCategories);
router.delete('/:id', authenticateToken, isAdmin, blogController.deletePost);

module.exports = router;
