"""Add seperate tables for rule details, claims

Revision ID: 49110ac3912f
Revises: f9c19016756d
Create Date: 2023-09-28 14:54:21.313903

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "49110ac3912f"
down_revision = "f9c19016756d"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "rule_result_details",
        sa.Column("id", sa.String(), nullable=False),
        sa.Column("prompt_rule_result_id", sa.String(), nullable=True),
        sa.Column("response_rule_result_id", sa.String(), nullable=True),
        sa.Column("score", sa.Boolean(), nullable=True),
        sa.Column("message", sa.String(), nullable=True),
        sa.ForeignKeyConstraint(
            ["prompt_rule_result_id"],
            ["prompt_rule_results.id"],
        ),
        sa.ForeignKeyConstraint(
            ["response_rule_result_id"],
            ["response_rule_results.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_rule_result_details_id"),
        "rule_result_details",
        ["id"],
        unique=False,
    )
    op.create_table(
        "hallucination_claims",
        sa.Column("id", sa.String(), nullable=False),
        sa.Column("rule_result_detail_id", sa.String(), nullable=False),
        sa.Column("claim", sa.String(), nullable=False),
        sa.Column("valid", sa.Boolean(), nullable=False),
        sa.Column("reason", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["rule_result_detail_id"],
            ["rule_result_details.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_hallucination_claims_id"),
        "hallucination_claims",
        ["id"],
        unique=False,
    )
    op.drop_column("prompt_rule_results", "rule_details")
    op.drop_column("response_rule_results", "rule_details")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "response_rule_results",
        sa.Column("rule_details", sa.VARCHAR(), autoincrement=False, nullable=True),
    )
    op.add_column(
        "prompt_rule_results",
        sa.Column("rule_details", sa.VARCHAR(), autoincrement=False, nullable=True),
    )
    op.drop_index(op.f("ix_hallucination_claims_id"), table_name="hallucination_claims")
    op.drop_table("hallucination_claims")
    op.drop_index(op.f("ix_rule_result_details_id"), table_name="rule_result_details")
    op.drop_table("rule_result_details")
    # ### end Alembic commands ###
