-- name: GetRecentlyExpiredQuotes :many
SELECT d.id, u.username, e.id, e.title, q.date_issued, q.valid_until
FROM quotes q
JOIN documents d on d.id = q.document_id
JOIN users u on u.id = d.user_id
JOIN enquiries e on e.id = q.enquiry_id 
WHERE valid_until < CURRENT_DATE AND valid_until >= DATE_SUB(CURRENT_DATE, INTERVAL ? DAY)
ORDER BY valid_until DESC;

-- name: GetExpiringSoonQuotes :many
SELECT d.id, u.username, e.id, e.title, q.date_issued, q.valid_until
FROM quotes q
JOIN documents d on d.id = q.document_id
JOIN users u on u.id = d.user_id
JOIN enquiries e on e.id = q.enquiry_id 
WHERE valid_until >= CURRENT_DATE AND valid_until <= DATE_ADD(CURRENT_DATE, INTERVAL ? DAY)
ORDER BY valid_until DESC;