-- Sub-SELECTs resolve natural keys to surrogate keys already loaded in DIM tables.
INSERT INTO FACT_TOURNAMENT (
    game_key, start_date_key, end_date_key, winner_org_key,
    event_name, gender, prize_pool_usd, num_participants, duration_days, has_club_points
)
SELECT
    (SELECT game_key FROM DIM_GAME WHERE game_id = ${game_id}),
    ${start_date_key},
    ${end_date_key},
    ${winner_org_id:isEmpty():ifElse('NULL',
        concat('(SELECT org_key FROM DIM_ORGANIZATION WHERE org_id = ', ${winner_org_id}, ')'))},
    '${event_name}',
    '${gender}',
    ${prize_pool_usd},
    ${num_participants},
    ${duration_days},
    ${has_club_points}
FROM DUAL
