import { NextResponse } from 'next/server';
import { mintTerminalToken, withOwnedJob } from '@/lib/agent-worker-proxy';

export const GET = async (
  _request: Request,
  context: { params: Promise<{ jobId: string }> },
) =>
  await withOwnedJob(context, (jobId) => {
    const minted = mintTerminalToken(jobId);
    return Promise.resolve(
      minted
        ? NextResponse.json(minted)
        : NextResponse.json(
            { error: 'Terminal is not configured on this deployment.' },
            { status: 503 },
          ),
    );
  });
