-- Step 3: Create and populate AI features tables

-- 3a. Create football_ai_features
CREATE TABLE IF NOT EXISTS football_ai_features (
    match_id TEXT PRIMARY KEY,
    home_elo FLOAT DEFAULT 1500.0,
    away_elo FLOAT DEFAULT 1500.0,
    home_home_elo FLOAT DEFAULT 1500.0,
    away_away_elo FLOAT DEFAULT 1500.0,
    home_form_elo FLOAT DEFAULT 1500.0,
    away_form_elo FLOAT DEFAULT 1500.0,
    elo_diff FLOAT DEFAULT 0.0,
    home_form_score FLOAT DEFAULT 50.0,
    away_form_score FLOAT DEFAULT 50.0,
    home_goals_avg_5 FLOAT DEFAULT 0.0,
    away_goals_avg_5 FLOAT DEFAULT 0.0,
    home_conceded_avg_5 FLOAT DEFAULT 0.0,
    away_conceded_avg_5 FLOAT DEFAULT 0.0,
    home_clean_sheet_rate FLOAT DEFAULT 0.0,
    away_clean_sheet_rate FLOAT DEFAULT 0.0,
    home_scoring_rate FLOAT DEFAULT 0.0,
    away_scoring_rate FLOAT DEFAULT 0.0,
    home_win_streak INT DEFAULT 0,
    away_win_streak INT DEFAULT 0,
    implied_home FLOAT DEFAULT 0.33,
    implied_draw FLOAT DEFAULT 0.33,
    implied_away FLOAT DEFAULT 0.33,
    implied_over25 FLOAT DEFAULT 0.5,
    implied_btts_yes FLOAT DEFAULT 0.5,
    odds_overround FLOAT DEFAULT 0.0,
    home_avg_possession FLOAT DEFAULT 50.0,
    away_avg_possession FLOAT DEFAULT 50.0,
    home_avg_shots_on_target FLOAT DEFAULT 0.0,
    away_avg_shots_on_target FLOAT DEFAULT 0.0,
    home_shot_conversion FLOAT DEFAULT 0.0,
    away_shot_conversion FLOAT DEFAULT 0.0,
    home_avg_corners FLOAT DEFAULT 0.0,
    away_avg_corners FLOAT DEFAULT 0.0,
    h2h_total INT DEFAULT 0,
    h2h_home_win_rate FLOAT DEFAULT 0.0,
    h2h_avg_goals FLOAT DEFAULT 0.0,
    h2h_over25_rate FLOAT DEFAULT 0.0,
    h2h_btts_rate FLOAT DEFAULT 0.0,
    referee_avg_cards FLOAT DEFAULT 0.0,
    referee_home_bias FLOAT DEFAULT 0.0,
    referee_avg_goals FLOAT DEFAULT 0.0,
    league_avg_goals FLOAT DEFAULT 0.0,
    league_home_win_pct FLOAT DEFAULT 0.0,
    league_over25_pct FLOAT DEFAULT 0.0,
    missing_players_impact FLOAT DEFAULT 0.0,
    calculator_ver TEXT DEFAULT 'v2.0',
    updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
    CONSTRAINT fk_football_ai_features_match FOREIGN KEY (match_id) REFERENCES matches(id) ON DELETE CASCADE
);

-- 3b. Create basketball_ai_features
CREATE TABLE IF NOT EXISTS basketball_ai_features (
    match_id TEXT PRIMARY KEY,
    home_elo FLOAT DEFAULT 1500.0,
    away_elo FLOAT DEFAULT 1500.0,
    home_home_elo FLOAT DEFAULT 1500.0,
    away_away_elo FLOAT DEFAULT 1500.0,
    home_form_elo FLOAT DEFAULT 1500.0,
    away_form_elo FLOAT DEFAULT 1500.0,
    elo_diff FLOAT DEFAULT 0.0,
    home_form_score FLOAT DEFAULT 50.0,
    away_form_score FLOAT DEFAULT 50.0,
    home_pts_avg_5 FLOAT DEFAULT 0.0,
    away_pts_avg_5 FLOAT DEFAULT 0.0,
    home_conceded_avg_5 FLOAT DEFAULT 0.0,
    away_conceded_avg_5 FLOAT DEFAULT 0.0,
    home_win_streak INT DEFAULT 0,
    away_win_streak INT DEFAULT 0,
    implied_home FLOAT DEFAULT 0.5,
    implied_away FLOAT DEFAULT 0.5,
    implied_over_total FLOAT DEFAULT 0.5,
    implied_spread_home FLOAT DEFAULT 0.5,
    odds_overround FLOAT DEFAULT 0.0,
    home_avg_pts FLOAT DEFAULT 0.0,
    away_avg_pts FLOAT DEFAULT 0.0,
    home_avg_rebounds FLOAT DEFAULT 0.0,
    away_avg_rebounds FLOAT DEFAULT 0.0,
    home_fg_pct FLOAT DEFAULT 0.0,
    away_fg_pct FLOAT DEFAULT 0.0,
    home_avg_three_pt_made FLOAT DEFAULT 0.0,
    away_avg_three_pt_made FLOAT DEFAULT 0.0,
    home_avg_turnovers FLOAT DEFAULT 0.0,
    away_avg_turnovers FLOAT DEFAULT 0.0,
    h2h_total INT DEFAULT 0,
    h2h_home_win_rate FLOAT DEFAULT 0.0,
    h2h_avg_pts FLOAT DEFAULT 0.0,
    h2h_avg_margin FLOAT DEFAULT 0.0,
    missing_players_impact FLOAT DEFAULT 0.0,
    calculator_ver TEXT DEFAULT 'v2.0',
    updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
    CONSTRAINT fk_basketball_ai_features_match FOREIGN KEY (match_id) REFERENCES matches(id) ON DELETE CASCADE
);
