"""add forms

Revision ID: 3d5e55da5fe4
Revises: f40ddf6f808c
Create Date: 2025-07-08 13:03:34.382654

"""

from alembic import op
import sqlalchemy as sa
from csirtmu.core.sqlalchemy.types import StringArray

# revision identifiers, used by Alembic.
revision = "3d5e55da5fe4"
down_revision = "f40ddf6f808c"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "form_step",
        sa.Column("clear_on_submit", sa.Boolean(), nullable=False),
        sa.Column("border", sa.Boolean(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.step.id"],
            name=op.f("fk_form_step_id_step"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_form_step")),
        schema="public",
    )
    op.create_table(
        "form_field",
        sa.Column("field_type", sa.String(), nullable=False),
        sa.Column("form_id", sa.Integer(), nullable=True),
        sa.Column("label_id", sa.Integer(), nullable=False),
        sa.Column("position", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["form_id"],
            ["public.form_step.id"],
            name=op.f("fk_form_field_form_id_form_step"),
        ),
        sa.ForeignKeyConstraint(
            ["label_id"], ["public.text.id"], name=op.f("fk_form_field_label_id_text")
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_form_field")),
        schema="public",
    )
    op.create_table(
        "checkbox",
        sa.Column("value", sa.Boolean(), nullable=False),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_checkbox_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_checkbox")),
        schema="public",
    )
    op.create_table(
        "composite_field",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_composite_field_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_composite_field")),
        schema="public",
    )
    op.create_table(
        "date_input",
        sa.Column("value", sa.Date(), nullable=True),
        sa.Column("min_value", sa.Date(), nullable=True),
        sa.Column("max_value", sa.Date(), nullable=True),
        sa.Column("format", sa.String(), nullable=True),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_date_input_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_date_input")),
        schema="public",
    )
    op.create_table(
        "file_uploader",
        sa.Column("type", StringArray(), nullable=True),
        sa.Column("accept_multiple_files", sa.Boolean(), nullable=False),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_file_uploader_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_file_uploader")),
        schema="public",
    )
    op.create_table(
        "multiselect",
        sa.Column("options", StringArray(), nullable=False),
        sa.Column("default", StringArray(), nullable=True),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("max_selections", sa.Integer(), nullable=True),
        sa.Column("placeholder_id", sa.Integer(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("accept_new_options", sa.Boolean(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_multiselect_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["placeholder_id"],
            ["public.text.id"],
            name=op.f("fk_multiselect_placeholder_id_text"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_multiselect")),
        schema="public",
    )
    op.create_table(
        "number_input",
        sa.Column("value", sa.Float(), nullable=True),
        sa.Column("min_value", sa.Float(), nullable=True),
        sa.Column("max_value", sa.Float(), nullable=True),
        sa.Column("step", sa.Float(), nullable=True),
        sa.Column("format", sa.String(), nullable=True),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("placeholder_id", sa.Integer(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("icon", sa.String(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_number_input_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["placeholder_id"],
            ["public.text.id"],
            name=op.f("fk_number_input_placeholder_id_text"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_number_input")),
        schema="public",
    )
    op.create_table(
        "radio",
        sa.Column("options", StringArray(), nullable=False),
        sa.Column("index", sa.Integer(), nullable=True),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("horizontal", sa.Boolean(), nullable=False),
        sa.Column("captions", StringArray(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_radio_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_radio")),
        schema="public",
    )
    op.create_table(
        "selectbox",
        sa.Column("options", StringArray(), nullable=False),
        sa.Column("index", sa.Integer(), nullable=True),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("placeholder_id", sa.Integer(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("accept_new_options", sa.Boolean(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_selectbox_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["placeholder_id"],
            ["public.text.id"],
            name=op.f("fk_selectbox_placeholder_id_text"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_selectbox")),
        schema="public",
    )
    op.create_table(
        "text_area",
        sa.Column("value", sa.String(), nullable=True),
        sa.Column("height", sa.Integer(), nullable=True),
        sa.Column("max_chars", sa.Integer(), nullable=True),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("placeholder_id", sa.Integer(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_text_area_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["placeholder_id"],
            ["public.text.id"],
            name=op.f("fk_text_area_placeholder_id_text"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_text_area")),
        schema="public",
    )
    op.create_table(
        "text_field",
        sa.Column("text_id", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_text_field_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["text_id"], ["public.text.id"], name=op.f("fk_text_field_text_id_text")
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_text_field")),
        schema="public",
    )
    op.create_table(
        "text_input",
        sa.Column("value", sa.String(), nullable=True),
        sa.Column("max_chars", sa.Integer(), nullable=True),
        sa.Column("type", sa.String(), nullable=False),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("autocomplete", sa.String(), nullable=True),
        sa.Column("placeholder_id", sa.Integer(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("icon", sa.String(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_text_input_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["placeholder_id"],
            ["public.text.id"],
            name=op.f("fk_text_input_placeholder_id_text"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_text_input")),
        schema="public",
    )
    op.create_table(
        "time_input",
        sa.Column("value", sa.Time(), nullable=True),
        sa.Column("help", sa.String(), nullable=True),
        sa.Column("step", sa.Integer(), nullable=True),
        sa.Column("label_visibility", sa.String(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.form_field.id"],
            name=op.f("fk_time_input_id_form_field"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_time_input")),
        schema="public",
    )
    op.create_table(
        "on_selection",
        sa.Column("selection_field_id", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.composite_field.id"],
            name=op.f("fk_on_selection_id_composite_field"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["selection_field_id"],
            ["public.form_field.id"],
            name=op.f("fk_on_selection_selection_field_id_form_field"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_on_selection")),
        schema="public",
    )
    op.create_table(
        "one_required",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.composite_field.id"],
            name=op.f("fk_one_required_id_composite_field"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_one_required")),
        schema="public",
    )
    op.create_table(
        "association_table",
        sa.Column("parent_id", sa.Integer(), nullable=False),
        sa.Column("child_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["child_id"],
            ["public.form_field.id"],
            name=op.f("fk_association_table_child_id_form_field"),
        ),
        sa.ForeignKeyConstraint(
            ["parent_id"],
            ["public.one_required.id"],
            name=op.f("fk_association_table_parent_id_one_required"),
        ),
        sa.PrimaryKeyConstraint(
            "parent_id", "child_id", name=op.f("pk_association_table")
        ),
        schema="public",
    )
    op.create_table(
        "selection_mapping",
        sa.Column("selection_id", sa.Integer(), nullable=False),
        sa.Column("option", sa.String(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["selection_id"],
            ["public.on_selection.id"],
            name=op.f("fk_selection_mapping_selection_id_on_selection"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_selection_mapping")),
        schema="public",
    )
    op.create_table(
        "selection_association_table",
        sa.Column("selection_mapping_id", sa.Integer(), nullable=True),
        sa.Column("option_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["option_id"],
            ["public.form_field.id"],
            name=op.f("fk_selection_association_table_option_id_form_field"),
        ),
        sa.ForeignKeyConstraint(
            ["selection_mapping_id"],
            ["public.selection_mapping.id"],
            name=op.f(
                "fk_selection_association_table_selection_mapping_id_selection_mapping"
            ),
        ),
        schema="public",
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("selection_association_table", schema="public")
    op.drop_table("selection_mapping", schema="public")
    op.drop_table("association_table", schema="public")
    op.drop_table("one_required", schema="public")
    op.drop_table("on_selection", schema="public")
    op.drop_table("time_input", schema="public")
    op.drop_table("text_input", schema="public")
    op.drop_table("text_field", schema="public")
    op.drop_table("text_area", schema="public")
    op.drop_table("selectbox", schema="public")
    op.drop_table("radio", schema="public")
    op.drop_table("number_input", schema="public")
    op.drop_table("multiselect", schema="public")
    op.drop_table("file_uploader", schema="public")
    op.drop_table("date_input", schema="public")
    op.drop_table("composite_field", schema="public")
    op.drop_table("checkbox", schema="public")
    op.drop_table("form_field", schema="public")
    op.drop_table("form_step", schema="public")
    # ### end Alembic commands ###
