/**
 * POST /:sessionId/unarchive endpoint - Unarchive a session
 */

import type { Request, Response } from 'express';
import { AgentService } from '../../../services/agent-service.js';
import { getErrorMessage, logError } from '../common.js';

export function createUnarchiveHandler(agentService: AgentService) {
  return async (req: Request, res: Response): Promise<void> => {
    try {
      const { sessionId } = req.params;
      const success = await agentService.unarchiveSession(sessionId);

      if (!success) {
        res.status(404).json({ success: false, error: 'Session not found' });
        return;
      }

      res.json({ success: true });
    } catch (error) {
      logError(error, 'Unarchive session failed');
      res.status(500).json({ success: false, error: getErrorMessage(error) });
    }
  };
}
