"""Add risk_assessment table

Revision ID: 010
Revises: 009
Create Date: 2026-04-23 21:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision: str = "010"
down_revision: Union[str, None] = "009"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "risk_assessment",
        sa.Column("id", sa.Integer(), primary_key=True, index=True),
        sa.Column("entity_type", sa.String(20), nullable=False),
        sa.Column("entity_id", sa.Integer(), nullable=False),
        sa.Column("entity_name", sa.String(200), nullable=True),
        sa.Column("risk_score", sa.Float(), default=0.0),
        sa.Column("sensitivity_score", sa.Float(), default=0.0),
        sa.Column("exposure_score", sa.Float(), default=0.0),
        sa.Column("protection_score", sa.Float(), default=0.0),
        sa.Column("details", sa.JSON(), nullable=True),
        sa.Column("created_at", sa.DateTime(), default=sa.func.now()),
        sa.Column("updated_at", sa.DateTime(), default=sa.func.now(), onupdate=sa.func.now()),
    )
    op.create_index("idx_risk_entity", "risk_assessment", ["entity_type", "entity_id"])


def downgrade() -> None:
    op.drop_index("idx_risk_entity", table_name="risk_assessment")
    op.drop_table("risk_assessment")
