"""add_v2_indexes

Revision ID: b005v2indexes
Revises: b004templates
Create Date: 2026-02-09 10:04:00.000000

"""
from typing import Sequence, Union

from alembic import op


# revision identifiers, used by Alembic.
revision: str = 'b005v2indexes'
down_revision: Union[str, Sequence[str], None] = 'b004templates'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Create performance indexes for V2 queries."""
    # ── Tests ───────────────────────────────────────────────────
    op.create_index('ix_tests_state', 'tests', ['state'])
    op.create_index('ix_tests_technique_id', 'tests', ['technique_id'])
    op.create_index('ix_tests_created_by', 'tests', ['created_by'])
    op.create_index('ix_tests_red_validation_status', 'tests', ['red_validation_status'])
    op.create_index('ix_tests_blue_validation_status', 'tests', ['blue_validation_status'])

    # ── Evidences ───────────────────────────────────────────────
    op.create_index('ix_evidences_test_id', 'evidences', ['test_id'])
    op.create_index('ix_evidences_team', 'evidences', ['team'])

    # ── Techniques (if not already present from MVP) ────────────
    op.create_index('ix_techniques_tactic', 'techniques', ['tactic'])
    op.create_index('ix_techniques_status_global', 'techniques', ['status_global'])
    op.create_index('ix_techniques_review_required', 'techniques', ['review_required'])


def downgrade() -> None:
    """Drop all V2 indexes."""
    # Techniques
    op.drop_index('ix_techniques_review_required', table_name='techniques')
    op.drop_index('ix_techniques_status_global', table_name='techniques')
    op.drop_index('ix_techniques_tactic', table_name='techniques')

    # Evidences
    op.drop_index('ix_evidences_team', table_name='evidences')
    op.drop_index('ix_evidences_test_id', table_name='evidences')

    # Tests
    op.drop_index('ix_tests_blue_validation_status', table_name='tests')
    op.drop_index('ix_tests_red_validation_status', table_name='tests')
    op.drop_index('ix_tests_created_by', table_name='tests')
    op.drop_index('ix_tests_technique_id', table_name='tests')
    op.drop_index('ix_tests_state', table_name='tests')
