"""initial

Revision ID: 82607cdce6ee
Revises:
Create Date: 2025-05-28 13:40:18.414894

"""

from collections.abc import Sequence

import sqlalchemy as sa
import sqlmodel
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "82607cdce6ee"
down_revision: str | None = None
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "submissions",
        sa.Column("tan_g", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
        sa.Column("pseudonym", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
        sa.Column("id", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_submissions_id"), "submissions", ["id"], unique=False)
    op.create_index(op.f("ix_submissions_pseudonym"), "submissions", ["pseudonym"], unique=False)
    op.create_index(op.f("ix_submissions_tan_g"), "submissions", ["tan_g"], unique=True)
    op.create_table(
        "submission_states",
        sa.Column(
            "state",
            sa.Enum(
                "UPLOADING",
                "UPLOADED",
                "DOWNLOADING",
                "DOWNLOADED",
                "DECRYPTING",
                "DECRYPTED",
                "VALIDATING",
                "VALIDATED",
                "ENCRYPTING",
                "ENCRYPTED",
                "ARCHIVING",
                "ARCHIVED",
                "REPORTED",
                "QCING",
                "QCED",
                "CLEANING",
                "CLEANED",
                "FINISHED",
                "ERROR",
                name="submissionstateenum",
            ),
            nullable=False,
        ),
        sa.Column("data", sa.JSON(), nullable=True),
        sa.Column("timestamp", sa.DateTime(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("submission_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.ForeignKeyConstraint(
            ["submission_id"],
            ["submissions.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_submission_states_id"), "submission_states", ["id"], unique=False)
    op.create_index(op.f("ix_submission_states_submission_id"), "submission_states", ["submission_id"], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_submission_states_submission_id"), table_name="submission_states")
    op.drop_index(op.f("ix_submission_states_id"), table_name="submission_states")
    op.drop_table("submission_states")
    op.drop_index(op.f("ix_submissions_tan_g"), table_name="submissions")
    op.drop_index(op.f("ix_submissions_pseudonym"), table_name="submissions")
    op.drop_index(op.f("ix_submissions_id"), table_name="submissions")
    op.drop_table("submissions")
    # ### end Alembic commands ###
