from __future__ import annotations

from alembic import op
import sqlalchemy as sa

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


def upgrade() -> None:
    op.add_column("validations", sa.Column("contact_id", sa.String(), nullable=True))
    op.add_column("validations", sa.Column("project", sa.String(length=180), nullable=True))
    op.add_column("validations", sa.Column("test_location", sa.String(length=180), nullable=True))
    op.add_column("validations", sa.Column("examiner_name", sa.String(length=180), nullable=True))
    op.add_column("validations", sa.Column("participants", sa.Text(), nullable=True))
    op.add_column("validations", sa.Column("operator_name", sa.String(length=180), nullable=True))
    op.add_column("validations", sa.Column("equipment_ids", sa.JSON(), nullable=False, server_default="[]"))
    op.add_column("validations", sa.Column("environment_conditions", sa.JSON(), nullable=False, server_default="{}"))
    op.add_column("validations", sa.Column("documentation_checklist", sa.JSON(), nullable=False, server_default="[]"))
    op.add_column("validations", sa.Column("performance_checklist", sa.JSON(), nullable=False, server_default="[]"))
    op.add_column("validations", sa.Column("programs", sa.JSON(), nullable=False, server_default="[]"))
    op.add_column("validations", sa.Column("loading_patterns", sa.JSON(), nullable=False, server_default="[]"))
    op.add_column("validations", sa.Column("measurement_data", sa.JSON(), nullable=False, server_default="[]"))
    op.add_column("validations", sa.Column("drying", sa.JSON(), nullable=False, server_default="{}"))
    op.add_column("validations", sa.Column("recommendations", sa.JSON(), nullable=False, server_default="[]"))
    op.add_column("validations", sa.Column("attachments", sa.JSON(), nullable=False, server_default="[]"))
    op.create_index("ix_validations_contact_id", "validations", ["contact_id"])
    op.create_foreign_key("fk_validations_contact_id_contacts", "validations", "contacts", ["contact_id"], ["id"])


def downgrade() -> None:
    op.drop_constraint("fk_validations_contact_id_contacts", "validations", type_="foreignkey")
    op.drop_index("ix_validations_contact_id", table_name="validations")
    for column in [
        "attachments",
        "recommendations",
        "drying",
        "measurement_data",
        "loading_patterns",
        "programs",
        "performance_checklist",
        "documentation_checklist",
        "environment_conditions",
        "equipment_ids",
        "operator_name",
        "participants",
        "examiner_name",
        "test_location",
        "project",
        "contact_id",
    ]:
        op.drop_column("validations", column)
