import type { FastifyInstance } from 'fastify';
import { list } from '../pty/registry.js';

export function registerSessionRoutes(app: FastifyInstance): void {
  app.get('/api/term/sessions', async (_req, reply) => {
    const active = list();
    return reply.code(200).send({
      sessions: active.map((s) => ({
        paneId: s.paneId,
        sessionId: s.sessionId,
        projectPath: s.projectPath,
        title: s.title ?? null,
        description: s.description ?? null,
        parentAgent: s.parentAgent ?? null,
        createdAt: s.createdAt.toISOString(),
        lastActivityAt: s.lastActivityAt.toISOString(),
      })),
    });
  });
}
