-- name: CreateTicket :one
INSERT INTO tickets (amount, total_odds)
VALUES ($1, $2)
RETURNING *;
-- name: CreateTicketOutcome :copyfrom
INSERT INTO ticket_outcomes (
        ticket_id,
        event_id,
        odd_id,
        home_team_name,
        away_team_name,
        market_id,
        market_name,
        odd,
        odd_name,
        odd_header,
        odd_handicap,
        expires
    )
VALUES (
        $1,
        $2,
        $3,
        $4,
        $5,
        $6,
        $7,
        $8,
        $9,
        $10,
        $11,
        $12
    );
-- name: GetAllTickets :many
SELECT *
FROM ticket_with_outcomes;
-- name: GetTicketByID :one
SELECT *
FROM ticket_with_outcomes
WHERE id = $1;
-- name: GetTicketOutcome :many
SELECT *
FROM ticket_outcomes
WHERE ticket_id = $1;
-- name: DeleteTicket :exec
DELETE FROM tickets
WHERE id = $1;
-- name: DeleteOldTickets :exec
Delete from tickets
where created_at < now() - interval '1 day';
-- name: DeleteTicketOutcome :exec
Delete from ticket_outcomes
where ticket_id = $1;