import { NextResponse } from 'next/server';

import { PrismaClient } from '@prisma/client';

const usingPrisma = false;
let prisma: PrismaClient;
if (usingPrisma) prisma = new PrismaClient();

export async function GET(request: Request) {
	try {
		const events = [
			{
				id: "1234",
				title: "Earthquake - Berlin Observatory",
				text1: "Logged by ",
				text2: "30 minutes ago",
				longitude: 10.4515, // Near Berlin, Germany
				latitude: 52.52,
			},
			{
				id: "2134",
				title: "New Observatory - Phuket, Thailand",
				text1: "Dr. Neil Armstrong",
				text2: "2 weeks ago",
				longitude: -122.4194,
				latitude: 37.7749,
			},
			{
				id: "2314",
				title: "Observatory Scientist Change",
				text1: "Dr. Samantha Green new lead scientist",
				text2: "1 month ago",
				longitude: 139.6917,
				latitude: 35.6762,
			},
		];

		// todo get earthquakes associated with observatories
		let observatories;
		if (usingPrisma) observatories = await prisma.observatories.findMany();

		if (observatories) {
			return NextResponse.json({ message: "Got observatories successfully", observatories }, { status: 200 });
		} else {
			return NextResponse.json({ message: "Got observatories successfully", observatories: events }, { status: 200 });
			// return NextResponse.json({ message: "Failed to get observatories" }, { status: 401 });
		}
	} catch (error) {
		console.error("Error in observatories endpoint:", error);
		return NextResponse.json({ message: "Internal Server Error" }, { status: 500 });
	} finally {
		if (usingPrisma) await prisma.$disconnect();
	}
}
