import { NextResponse } from "next/server";
import fs from "fs";

const RESPONSE_FILE = "/tmp/horus-mc-response.txt";

export async function GET() {
  try {
    // Check if there's a response file
    if (fs.existsSync(RESPONSE_FILE)) {
      const response = fs.readFileSync(RESPONSE_FILE, "utf-8").trim();
      
      if (response) {
        // Clear the file after reading
        fs.writeFileSync(RESPONSE_FILE, "");
        return NextResponse.json({ response });
      }
    }
    
    return NextResponse.json({ response: null });
  } catch (error) {
    console.error("Error:", error);
    return NextResponse.json({ response: null });
  }
}
