import { handleDockScanInsertedNotification } from "../dockdoorScanning/dockdoor.socket.notifications.js";
import { createLogger } from "../logger/logger.controller.js";
import { handleLogInsertedNotification } from "../logger/logger.socket.notifications.js";

const log = createLogger({
	module: "db",
	subModule: "notifications-router",
});

type DbNotification = {
	channel: string;
	payload: {
		table: string;
		action: "INSERT" | "UPDATE" | "DELETE";
		id: string;
	};
};

export async function handleDbNotification(notification: DbNotification) {
	const { channel, payload } = notification;

	switch (channel) {
		case "logs_inserted":
			await handleLogInsertedNotification(payload.id);
			return;

		// case "labels_inserted":
		// 	await handleLabelInsertedNotification(payload.id);
		// 	return;

		case "dock_scan_inserted":
			await handleDockScanInsertedNotification(payload.id);
			return;

		default:
			log.warn(
				{ stack: notification },
				`Unhandled DB notification channel: ${channel}`,
			);
	}
}
