"""add simulations table

Revision ID: 0002
Revises: 0001
Create Date: 2026-05-26 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa


revision = "0002"
down_revision = "0001"
branch_labels = None
depends_on = None


def upgrade():
    op.create_table(
        "simulations",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("engagement_id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.Column("mitre_technique_id", sa.String(length=32), nullable=True),
        sa.Column("mitre_technique_name", sa.String(length=255), nullable=True),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("commands", sa.Text(), nullable=True),
        sa.Column("prerequisites", sa.Text(), nullable=True),
        sa.Column("executed_at", sa.DateTime(), nullable=True),
        sa.Column("execution_result", sa.Text(), nullable=True),
        sa.Column("log_source", sa.Text(), nullable=True),
        sa.Column("logs", sa.Text(), nullable=True),
        sa.Column("soc_comment", sa.Text(), nullable=True),
        sa.Column("incident_number", sa.String(length=128), nullable=True),
        sa.Column(
            "status",
            sa.Enum("pending", "in_progress", "review_required", "done", name="simulation_status"),
            nullable=False,
        ),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("created_by_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["engagement_id"], ["engagements.id"], ondelete="CASCADE",
            name="fk_simulations_engagement_id_engagements",
        ),
        sa.ForeignKeyConstraint(
            ["created_by_id"], ["users.id"], ondelete="RESTRICT",
            name="fk_simulations_created_by_id_users",
        ),
    )
    op.create_index("ix_simulations_engagement_id", "simulations", ["engagement_id"])
    op.create_index("ix_simulations_created_by_id", "simulations", ["created_by_id"])


def downgrade():
    op.drop_index("ix_simulations_created_by_id", table_name="simulations")
    op.drop_index("ix_simulations_engagement_id", table_name="simulations")
    op.drop_table("simulations")
    sa.Enum(name="simulation_status").drop(op.get_bind(), checkfirst=True)
