-- name: CreateRaffle :one
INSERT INTO raffles (company_id, name, expires_at, type)
VALUES ($1, $2, $3, $4)
RETURNING *;

-- name: GetRafflesOfCompany :many
SELECT * FROM raffles WHERE company_id = $1;

-- name: UpdateRaffle :exec
UPDATE raffles
SET name = $1,
    expires_at = $2,
    status = $3
WHERE id = $4;

-- name: UpdateRaffleTicketStatus :exec
UPDATE raffle_tickets
SET is_active = $1
WHERE id = $2;

-- name: CreateRaffleTicket :one
INSERT INTO raffle_tickets (raffle_id, user_id)
VALUES ($1, $2)
RETURNING *;

-- name: GetUserRaffleTickets :many
SELECT 
    rt.id AS ticket_id,
    rt.user_id,
    r.name,
    r.type,
    r.expires_at,
    r.status
FROM raffle_tickets rt
JOIN raffles r ON rt.raffle_id = r.id
WHERE rt.user_id = $1;
