"""create energy scores table

Revision ID: 20260117_0004
Revises: 20260117_0003
Create Date: 2026-01-17 00:00:00.000000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '20260117_0004'
down_revision = '20260117_0003'
branch_labels = None
depends_on = None


def upgrade() -> None:
    """Create energy_scores table."""
    op.create_table(
        'energy_scores',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('match_id', sa.Integer(), nullable=False),
        sa.Column('team_id', sa.Integer(), nullable=False),
        sa.Column('score', sa.Float(), nullable=False),
        sa.Column('confidence', sa.Float(), nullable=False, server_default='0.0'),
        sa.Column('sources_used', sa.JSON(), nullable=False, server_default='[]'),
        sa.Column('twitter_score', sa.Float(), nullable=True),
        sa.Column('reddit_score', sa.Float(), nullable=True),
        sa.Column('rss_score', sa.Float(), nullable=True),
        sa.Column('temporal_factor', sa.Float(), nullable=True),
        sa.Column('twitter_weight', sa.Float(), nullable=True),
        sa.Column('reddit_weight', sa.Float(), nullable=True),
        sa.Column('rss_weight', sa.Float(), nullable=True),
        sa.Column('created_at', sa.DateTime(), nullable=False, server_default=sa.func.now()),
        sa.Column('updated_at', sa.DateTime(), nullable=False, server_default=sa.func.now()),
        sa.PrimaryKeyConstraint('id')
    )

    # Create indexes for performance
    op.create_index('idx_energy_scores_match_team', 'energy_scores', ['match_id', 'team_id'])
    op.create_index('idx_energy_scores_score', 'energy_scores', ['score'])
    op.create_index('idx_energy_scores_confidence', 'energy_scores', ['confidence'])
    op.create_index('idx_energy_scores_created_at', 'energy_scores', ['created_at'])
    op.create_index('idx_energy_scores_updated_at', 'energy_scores', ['updated_at'])
    op.create_index(op.f('ix_energy_scores_id'), 'energy_scores', ['id'])
    op.create_index(op.f('ix_energy_scores_match_id'), 'energy_scores', ['match_id'])
    op.create_index(op.f('ix_energy_scores_team_id'), 'energy_scores', ['team_id'])


def downgrade() -> None:
    """Drop energy_scores table."""
    op.drop_index(op.f('ix_energy_scores_team_id'), table_name='energy_scores')
    op.drop_index(op.f('ix_energy_scores_match_id'), table_name='energy_scores')
    op.drop_index(op.f('ix_energy_scores_id'), table_name='energy_scores')
    op.drop_index('idx_energy_scores_updated_at', table_name='energy_scores')
    op.drop_index('idx_energy_scores_created_at', table_name='energy_scores')
    op.drop_index('idx_energy_scores_confidence', table_name='energy_scores')
    op.drop_index('idx_energy_scores_score', table_name='energy_scores')
    op.drop_index('idx_energy_scores_match_team', table_name='energy_scores')
    op.drop_table('energy_scores')
