-- name: CreateBooking :one INSERT INTO bookings (id, user_id, project_id, slot_id, phone, status, remark, confirm_token) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING *; -- name: GetBooking :one SELECT * FROM bookings WHERE id = ?; -- name: ListBookingsByPhone :many SELECT * FROM bookings WHERE phone = ? ORDER BY created_at DESC; -- name: ListBookings :many SELECT * FROM bookings ORDER BY created_at DESC LIMIT ? OFFSET ?; -- name: ListBookingsByStatus :many SELECT * FROM bookings WHERE status = ? ORDER BY created_at DESC LIMIT ? OFFSET ?; -- name: CountBookingsByProject :one SELECT COUNT(*) FROM bookings WHERE project_id = ?; -- name: UpdateBookingStatus :one UPDATE bookings SET status = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? RETURNING *; -- name: CancelBooking :one UPDATE bookings SET status = 'cancelled_by_user', updated_at = CURRENT_TIMESTAMP WHERE id = ? AND phone = ? AND status IN ('pending', 'confirmed') RETURNING *;