import { createAudioPlayer } from "expo-audio";
import * as Haptics from "expo-haptics";

export type ScanFeedback = {
	type: "good" | "bad" | "scan";
	sound?: boolean;
	vibrate?: boolean;
	led?: boolean;
};

const scan = createAudioPlayer(require("../../assets/sounds/scan.wav"));
const goodSound = createAudioPlayer(require("../../assets/sounds/good.wav"));
const badSound = createAudioPlayer(require("../../assets/sounds/bad.wav"));

export async function scannerFeedback({
	type,
	sound = true,
	vibrate = true,
	led = true,
}: ScanFeedback) {
	if (sound) {
		const player =
			type === "scan" ? scan : type === "good" ? goodSound : badSound;
		player.seekTo(0);
		player.play();
	}

	if (vibrate) {
		await Haptics.notificationAsync(
			type === "good" || type === "scan"
				? Haptics.NotificationFeedbackType.Success
				: Haptics.NotificationFeedbackType.Error,
		);
	}

	if (led) {
		// Zebra LED hook goes here
		// More below 👇
	}
}
