-- name: InsertNonLiveOdd :exec
INSERT INTO odds (
    event_id,
    fi,
    raw_event_id,
    market_type,
    market_name,
    market_category,
    market_id,
    header,
    name,
    handicap,
    odds_value,
    section,
    category,
    raw_odds,
    is_active,
    source,
    fetched_at
) VALUES (
    $1, $2, $3, $4, $5, $6, $7, 
    $8, $9, $10, $11, $12, $13, $14,
    true, 'b365api', now()
)
ON CONFLICT (event_id, market_id, header, name, handicap) DO UPDATE SET
    odds_value     = EXCLUDED.odds_value,
    raw_odds       = EXCLUDED.raw_odds,
    market_type    = EXCLUDED.market_type,
    market_name    = EXCLUDED.market_name,
    market_category = EXCLUDED.market_category,
    fetched_at     = now(),
    is_active      = true,
    source         = 'b365api',
    fi             = EXCLUDED.fi,
    raw_event_id   = EXCLUDED.raw_event_id;


-- name: GetUpcomingEventIDs :many
SELECT id FROM events
WHERE is_live = false;
