/**
 * Broker CSV Template Download
 * GET /api/real-estate/brokers/template
 */

import { NextResponse } from "next/server";

export const dynamic = "force-dynamic";

export async function GET() {
  const headers = [
    "nameEn",
    "nameAr",
    "phone",
    "email",
    "whatsappNumber",
    "licenseNumber",
    "workStartTime",
    "workEndTime",
    "maxViewingsPerDay",
  ];

  const examples = [
    [
      "Ahmed Hassan",
      "أحمد حسن",
      "+97455001234",
      "ahmed@example.com",
      "+97455001234",
      "BR-2025-001",
      "09:00",
      "18:00",
      "6",
    ],
    [
      "Sarah Al-Thani",
      "سارة آل ثاني",
      "+97455005678",
      "sarah@example.com",
      "+97455005678",
      "BR-2025-002",
      "10:00",
      "19:00",
      "8",
    ],
  ];

  const csvRows = [
    headers.join(","),
    ...examples.map((row) =>
      row.map((cell) => (cell.includes(",") ? `"${cell}"` : cell)).join(","),
    ),
  ];

  return new NextResponse(csvRows.join("\n"), {
    headers: {
      "Content-Type": "text/csv",
      "Content-Disposition":
        "attachment; filename=broker-import-template.csv",
    },
  });
}
