import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { getPublicWarungBySlug } from '$lib/server/warung';

export const GET: RequestHandler = async ({ params }) => {
	try {
		const warung = await getPublicWarungBySlug(params.slug);

		if (!warung) {
			return json({ success: false, message: 'Warung tidak ditemukan.' }, { status: 404 });
		}

		return json({ success: true, warung });
	} catch {
		return json({ success: false, message: 'Gagal mengambil data warung.' }, { status: 500 });
	}
};
