"""add_validator_type_to_code_quality

Revision ID: f4a5b6c7d8e9
Revises: e3f4a5b6c7d8
Create Date: 2025-12-21

This migration adds validator_type column to architecture scans and violations
to support multiple validator types (architecture, security, performance).
"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "f4a5b6c7d8e9"
down_revision: str | None = "e3f4a5b6c7d8"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # Add validator_type to architecture_scans table
    op.add_column(
        "architecture_scans",
        sa.Column(
            "validator_type",
            sa.String(length=20),
            nullable=False,
            server_default="architecture",
        ),
    )
    op.create_index(
        op.f("ix_architecture_scans_validator_type"),
        "architecture_scans",
        ["validator_type"],
        unique=False,
    )

    # Add validator_type to architecture_violations table
    op.add_column(
        "architecture_violations",
        sa.Column(
            "validator_type",
            sa.String(length=20),
            nullable=False,
            server_default="architecture",
        ),
    )
    op.create_index(
        op.f("ix_architecture_violations_validator_type"),
        "architecture_violations",
        ["validator_type"],
        unique=False,
    )

    # Add validator_type to architecture_rules table
    op.add_column(
        "architecture_rules",
        sa.Column(
            "validator_type",
            sa.String(length=20),
            nullable=False,
            server_default="architecture",
        ),
    )
    op.create_index(
        op.f("ix_architecture_rules_validator_type"),
        "architecture_rules",
        ["validator_type"],
        unique=False,
    )


def downgrade() -> None:
    # Drop indexes first
    op.drop_index(
        op.f("ix_architecture_rules_validator_type"),
        table_name="architecture_rules",
    )
    op.drop_index(
        op.f("ix_architecture_violations_validator_type"),
        table_name="architecture_violations",
    )
    op.drop_index(
        op.f("ix_architecture_scans_validator_type"),
        table_name="architecture_scans",
    )

    # Drop columns
    op.drop_column("architecture_rules", "validator_type")
    op.drop_column("architecture_violations", "validator_type")
    op.drop_column("architecture_scans", "validator_type")
