-- name: GetEventBySlug :one
SELECT * FROM events WHERE slug = ?;

-- name: GetEventByAdminToken :one
SELECT * FROM events WHERE admin_token = ?;

-- name: CreateEvent :one
INSERT INTO events (slug, title, date, time, location, admin_token)
VALUES (?, ?, ?, ?, ?, ?)
RETURNING *;

-- name: UpdateEvent :exec
UPDATE events SET title = ?, date = ?, time = ?, location = ? WHERE id = ?;

-- name: DeleteEvent :exec
DELETE FROM events WHERE id = ?;

-- name: ListSlots :many
SELECT * FROM slots WHERE event_id = ? ORDER BY sort_order, id;

-- name: GetSlot :one
SELECT * FROM slots WHERE id = ?;

-- name: CreateSlot :one
INSERT INTO slots (event_id, name, emoji, max_claims, sort_order)
VALUES (?, ?, ?, ?, ?)
RETURNING *;

-- name: UpdateSlot :exec
UPDATE slots SET name = ?, emoji = ?, max_claims = ? WHERE id = ?;

-- name: DeleteSlot :exec
DELETE FROM slots WHERE id = ?;

-- name: ListClaimsBySlot :many
SELECT * FROM claims WHERE slot_id = ? ORDER BY created_at;

-- name: ListClaimsByEvent :many
SELECT c.* FROM claims c
JOIN slots s ON c.slot_id = s.id
WHERE s.event_id = ?
ORDER BY c.slot_id, c.created_at;

-- name: CreateClaim :one
INSERT INTO claims (slot_id, name, note)
VALUES (?, ?, ?)
RETURNING *;

-- name: DeleteClaim :exec
DELETE FROM claims WHERE id = ?;

-- name: CountClaimsBySlot :one
SELECT COUNT(*) FROM claims WHERE slot_id = ?;

-- name: ListRsvps :many
SELECT * FROM rsvps WHERE event_id = ? ORDER BY created_at;

-- name: CreateRsvp :one
INSERT INTO rsvps (event_id, name, note)
VALUES (?, ?, ?)
RETURNING *;

-- name: DeleteRsvp :exec
DELETE FROM rsvps WHERE id = ?;

-- name: CountRsvps :one
SELECT COUNT(*) FROM rsvps WHERE event_id = ?;
