"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const index_1 = require("../index");
const auth_1 = require("../middleware/auth");
const router = (0, express_1.Router)();
// POST /api/bookings - Public: Create new booking
router.post('/', async (req, res) => {
    try {
        const { name, phone, email, branch, category, treatment, date, time, notes } = req.body;
        if (!name || !phone || !branch || !category || !treatment || !date || !time) {
            return res.status(400).json({ message: 'Data booking tidak lengkap' });
        }
        const booking = await index_1.prisma.booking.create({
            data: { name, phone, email, branch, category, treatment, date, time, notes, status: 'pending' }
        });
        res.status(201).json({ message: 'Reservasi berhasil dikirim', booking });
    }
    catch (error) {
        res.status(500).json({ message: 'Gagal membuat reservasi', error: error instanceof Error ? error.message : '' });
    }
});
// GET /api/bookings - Admin: Get all bookings
router.get('/', auth_1.authMiddleware, async (req, res) => {
    try {
        const bookings = await index_1.prisma.booking.findMany({
            orderBy: { createdAt: 'desc' }
        });
        res.json(bookings);
    }
    catch (error) {
        res.status(500).json({ message: 'Gagal mengambil reservasi', error: error instanceof Error ? error.message : '' });
    }
});
// PUT /api/bookings/:id/status - Admin: Update booking status
router.put('/:id/status', auth_1.authMiddleware, async (req, res) => {
    try {
        const { status } = req.body;
        if (!status) {
            return res.status(400).json({ message: 'Status diperlukan' });
        }
        const booking = await index_1.prisma.booking.update({
            where: { id: parseInt(req.params.id) },
            data: { status }
        });
        res.json(booking);
    }
    catch (error) {
        res.status(500).json({ message: 'Gagal mengupdate status', error: error instanceof Error ? error.message : '' });
    }
});
// DELETE /api/bookings/:id - Admin: Delete booking
router.delete('/:id', auth_1.authMiddleware, async (req, res) => {
    try {
        await index_1.prisma.booking.delete({ where: { id: parseInt(req.params.id) } });
        res.json({ message: 'Reservasi berhasil dihapus' });
    }
    catch (error) {
        res.status(500).json({ message: 'Gagal menghapus reservasi', error: error instanceof Error ? error.message : '' });
    }
});
exports.default = router;
//# sourceMappingURL=bookings.js.map