// server/api/config/anjungan/[id].delete.ts
import { getConfigDb } from '~/server/utils/configDb';

export default defineEventHandler((event) => {
  const id = Number(getRouterParam(event, 'id'));
  if (!id) throw createError({ statusCode: 400, message: 'ID tidak valid' });

  const db = getConfigDb();
  const existing = db.prepare('SELECT * FROM config_anjungan WHERE id = ?').get(id) as any;
  if (!existing) throw createError({ statusCode: 404, message: 'Anjungan tidak ditemukan' });

  db.prepare('DELETE FROM config_anjungan WHERE id = ?').run(id);
  return { success: true, message: `Anjungan ${existing.namaAnjungan} berhasil dihapus` };
});
