-- name: CreateBooking :one
INSERT INTO bookings (user_id, service_id, event_date, address, notes, status, service_option, event_type)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, user_id, service_id, event_date, address, notes, created_at, status, service_option, event_type;

-- name: ListBookingsByUser :many
SELECT id, user_id, service_id, event_date, address, notes, created_at, status, service_option, event_type
FROM bookings
WHERE user_id = $1
ORDER BY event_date DESC;

-- name: ListBookingsWithServiceByUser :many
SELECT 
    b.id,
    b.user_id,
    b.service_id,
    b.event_date,
    b.address,
    b.notes,
    b.created_at,
    b.status,
    b.service_option,
    b.event_type,
    s.name as service_name,
    s.description as service_description,
    s.price_cents as service_price_cents
FROM bookings b
JOIN services s ON b.service_id = s.id
WHERE b.user_id = $1
ORDER BY b.event_date DESC;

-- name: GetBooking :one
SELECT id, user_id, service_id, event_date, address, notes, created_at, status, service_option, event_type
FROM bookings
WHERE id = $1;

-- name: ListAllBookingsWithDetails :many
SELECT 
    b.id,
    b.user_id,
    b.service_id,
    b.event_date,
    b.address,
    b.notes,
    b.created_at,
    b.status,
    b.service_option,
    b.event_type,
    u.email as user_email,
    s.name as service_name,
    s.description as service_description,
    s.price_cents as service_price_cents
FROM bookings b
JOIN users u ON b.user_id = u.id
JOIN services s ON b.service_id = s.id
ORDER BY b.created_at DESC;

-- name: UpdateBookingStatus :exec
UPDATE bookings
SET status = $2
WHERE id = $1;
