CREATE TABLE IF NOT EXISTS virtual_games (
    id BIGSERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    provider VARCHAR(100) NOT NULL,
    category VARCHAR(100) NOT NULL,
    min_bet DECIMAL(15,2) NOT NULL,
    max_bet DECIMAL(15,2) NOT NULL,
    volatility VARCHAR(50) NOT NULL,
    rtp DECIMAL(5,2) NOT NULL,
    is_featured BOOLEAN DEFAULT false,
    popularity_score INTEGER DEFAULT 0,
    thumbnail_url TEXT,
    created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE user_game_interactions (
    id BIGSERIAL PRIMARY KEY,
    user_id BIGINT NOT NULL REFERENCES users(id),
    game_id BIGINT NOT NULL REFERENCES virtual_games(id),
    interaction_type VARCHAR(50) NOT NULL, -- 'view', 'play', 'bet', 'favorite'
    amount DECIMAL(15,2),
    duration_seconds INTEGER,
    created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX idx_user_game_interactions_user ON user_game_interactions(user_id);
CREATE INDEX idx_user_game_interactions_game ON user_game_interactions(game_id);