/**
 * Viewing CSV Template Download
 * GET /api/real-estate/viewings/template
 */

import { NextResponse } from "next/server";

export const dynamic = "force-dynamic";

export async function GET() {
  const headers = [
    "propertyId",
    "clientName",
    "clientPhone",
    "clientEmail",
    "viewingType",
    "viewingDate",
    "viewingTime",
    "duration",
  ];

  const examples = [
    [
      "<property-id>",
      "John Smith",
      "+97455009999",
      "john@example.com",
      "INDIVIDUAL",
      "2026-04-15",
      "10:00",
      "30",
    ],
    [
      "<property-id>",
      "Maria Garcia",
      "+97455008888",
      "maria@example.com",
      "SECOND_VIEWING",
      "2026-04-16",
      "14:30",
      "45",
    ],
  ];

  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=viewing-import-template.csv",
    },
  });
}
