// backend/routes/assistantRoutes.js
import express from 'express';
import authMiddleware from '../middlewares/authMiddleware.js';
import {
  createAssistant,
  getAssistants,
  deleteAssistant,
  assignFileToAssistant,
  getFilesByAssistant,
  assignMultipleFilesToAssistant,
  removeFileFromAssistant,
} from '../controllers/assistantController.js';
import { generateEmbeddings } from '../controllers/embeddingController.js';
import { getAssistantById } from '../controllers/assistantController.js'; // import the new function

const router = express.Router();

// Apply the auth middleware to all routes in this router
router.use(authMiddleware);

// Create a new assistant
router.post('/', createAssistant);

// Get all assistants for the authenticated user
router.get('/', getAssistants);

// New endpoint: Get a single assistant by ID
router.get('/:id', getAssistantById);

// Delete an assistant by ID
router.delete('/:id', deleteAssistant);

// Assign a single file to an assistant
router.post('/:assistantId/files/:fileId', assignFileToAssistant);

// Get files assigned to a specific assistant
router.get('/:assistantId/files', getFilesByAssistant);

// Assign multiple files to an assistant
router.post('/:assistantId/files', assignMultipleFilesToAssistant);

// Remove a file from an assistant
router.delete('/:assistantId/files/:fileId', removeFileFromAssistant);

// New endpoint: Generate embeddings for an assistant (triggered by gear icon)
router.post('/:assistantId/embeddings', generateEmbeddings);

export default router;

