from __future__ import annotations

from alembic import op

revision = "202607110001"
down_revision = "202607100002"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute("ALTER TABLE validations ALTER COLUMN status TYPE varchar(40) USING status::text")
    op.execute(
        """
        UPDATE validations
        SET status = CASE status
            WHEN 'draft' THEN 'ENTWURF'
            WHEN 'ready_for_report' THEN 'BEREIT_ZUR_PRUEFUNG'
            WHEN 'in_progress' THEN 'IN_PRUEFUNG'
            WHEN 'completed' THEN 'ABGESCHLOSSEN'
            ELSE status
        END
        """
    )
    op.execute("ALTER TABLE validations ALTER COLUMN status SET DEFAULT 'ENTWURF'")


def downgrade() -> None:
    op.execute(
        """
        UPDATE validations
        SET status = CASE status
            WHEN 'ENTWURF' THEN 'draft'
            WHEN 'BEREIT_ZUR_PRUEFUNG' THEN 'ready_for_report'
            WHEN 'IN_PRUEFUNG' THEN 'in_progress'
            WHEN 'FREIGEGEBEN' THEN 'ready_for_report'
            WHEN 'ABGESCHLOSSEN' THEN 'completed'
            WHEN 'STORNIERT' THEN 'completed'
            ELSE status
        END
        """
    )
