import { Router } from 'express';
import { aiController } from '../controllers/ai.controller';

/**
 * Router for AI-powered task management endpoints
 */
const router = Router();

/**
 * @route   POST /api/ai/create-task
 * @desc    Create a task from natural language input
 * @access  Private
 * @body    {
 *            prompt: string,
 *            projectId?: string,
 *            context?: {
 *              currentTasks?: string[],
 *              completedTasks?: string[],
 *              projectDescription?: string,
 *              userRole?: string
 *            }
 *          }
 */
router.post('/create-task', (req, res, next) => 
  aiController.createTask(req, res, next)
);

/**
 * @route   PUT /api/ai/update-context/:taskId
 * @desc    Update AI context for a task with user feedback
 * @access  Private
 * @params  taskId - The ID of the task to update
 * @body    { feedback: string }
 */
router.put('/update-context/:taskId', (req, res, next) => 
  aiController.updateTaskContext(req, res, next)
);

/**
 * @route   GET /api/ai/suggestions/:projectId
 * @desc    Get AI-powered task suggestions for a project
 * @access  Private
 * @params  projectId - The ID of the project
 * @query   {
 *            projectDescription: string,
 *            completedTasks: string (comma-separated),
 *            currentTasks: string (comma-separated),
 *            goals: string (comma-separated)
 *          }
 */
router.get('/suggestions/:projectId', (req, res, next) => 
  aiController.getTaskSuggestions(req, res, next)
);

/**
 * @route   POST /api/ai/breakdown/:taskId
 * @desc    Break down a task into subtasks using AI
 * @access  Private
 * @params  taskId - The ID of the task to break down
 * @body    {
 *            taskDescription: string,
 *            context?: string
 *          }
 */
router.post('/breakdown/:taskId', (req, res, next) => 
  aiController.breakdownTask(req, res, next)
);

/**
 * @route   GET /api/ai/health
 * @desc    Check health status of AI services
 * @access  Private
 */
router.get('/health', (req, res, next) => 
  aiController.getHealthStatus(req, res, next)
);

/**
 * @route   GET /api/ai/usage
 * @desc    Get usage statistics for AI services
 * @access  Private
 */
router.get('/usage', (req, res, next) => 
  aiController.getUsageStats(req, res, next)
);

/**
 * @route   POST /api/ai/warm-cache
 * @desc    Warm cache with common queries for a project
 * @access  Private
 * @body    { projectId: string }
 */
router.post('/warm-cache', (req, res, next) => 
  aiController.warmCache(req, res, next)
);

/**
 * @route   POST /api/ai/test-connection
 * @desc    Test connection to AI services
 * @access  Private
 */
router.post('/test-connection', (req, res, next) => 
  aiController.testConnection(req, res, next)
);

export default router;