import type { Request, Response } from "express";
import { stationSoundService } from "./station-sound.service";

export async function listStationSounds(req: Request, res: Response) {
    const { shopId, stationId } = req.params as any;
    const sounds = await stationSoundService.list(shopId, stationId);
    res.json(sounds);
}

export async function upsertStationSound(req: Request, res: Response) {
    const { shopId, stationId } = req.params as any;
    const { event, label } = req.body as { event: string; label?: string };

    if (!event) {
        res.status(400).json({ error: "event is required" });
        return;
    }

    if (!req.file) {
        res.status(400).json({ error: "Audio file is required" });
        return;
    }

    const sound = await stationSoundService.upsert(shopId, stationId, event, req.file, label);
    res.status(201).json(sound);
}

export async function deleteStationSound(req: Request, res: Response) {
    const { shopId, stationId, soundId } = req.params as any;
    await stationSoundService.remove(shopId, stationId, soundId);
    res.status(204).send();
}

