"""add interview workflow tables

Revision ID: b2c3d4e5f6a7
Revises: d4e5f6a7b8c9
Create Date: 2026-10-28 09:50:00.000000

"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "b2c3d4e5f6a7"
down_revision: Union[str, Sequence[str], None] = "d4e5f6a7b8c9"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "interview_workflows",
        sa.Column("workflow_id", sa.String(length=64), primary_key=True),
        sa.Column("company_id", sa.String(length=128), nullable=False, server_default=""),
        sa.Column("user_id", sa.String(length=128), nullable=True),
        sa.Column("interview_id", sa.String(length=128), nullable=True),
        sa.Column("title", sa.String(length=512), nullable=False),
        sa.Column("role_title", sa.String(length=512), nullable=False),
        sa.Column("job_description", sa.Text(), nullable=True),
        sa.Column("skills", sa.JSON(), nullable=False),
        sa.Column("experience_level", sa.String(length=128), nullable=True),
        sa.Column("duration_minutes", sa.Integer(), nullable=True),
        sa.Column("language", sa.String(length=32), nullable=False),
        sa.Column("difficulty", sa.String(length=32), nullable=False),
        sa.Column("mode", sa.String(length=64), nullable=False),
        sa.Column("persona_id", sa.String(length=128), nullable=True),
        sa.Column("status", sa.String(length=64), nullable=False),
        sa.Column("version", sa.Integer(), nullable=False),
        sa.Column("meta", sa.JSON(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
    )
    op.create_index("ix_interview_workflows_company_id", "interview_workflows", ["company_id"])
    op.create_index("ix_interview_workflows_user_id", "interview_workflows", ["user_id"])
    op.create_index("ix_interview_workflows_interview_id", "interview_workflows", ["interview_id"])
    op.create_index("ix_interview_workflows_status", "interview_workflows", ["status"])
    op.create_index(
        "ix_interview_workflows_company_updated",
        "interview_workflows",
        ["company_id", "updated_at"],
    )

    op.create_table(
        "interview_workflow_questions",
        sa.Column("id", sa.String(length=64), primary_key=True),
        sa.Column("workflow_id", sa.String(length=64), nullable=False),
        sa.Column("question_id", sa.String(length=128), nullable=False),
        sa.Column("text", sa.Text(), nullable=False),
        sa.Column("question_type", sa.String(length=64), nullable=False),
        sa.Column("skill", sa.String(length=256), nullable=True),
        sa.Column("difficulty", sa.String(length=32), nullable=True),
        sa.Column("category", sa.String(length=128), nullable=True),
        sa.Column("evaluation_criteria", sa.JSON(), nullable=False),
        sa.Column("source", sa.String(length=32), nullable=False),
        sa.Column("position", sa.Integer(), nullable=False),
        sa.Column("response_format", sa.String(length=64), nullable=True),
        sa.Column("response_time_seconds", sa.Integer(), nullable=True),
        sa.Column("meta", sa.JSON(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.UniqueConstraint("workflow_id", "question_id", name="uq_workflow_question_id"),
    )
    op.create_index(
        "ix_interview_workflow_questions_workflow_id",
        "interview_workflow_questions",
        ["workflow_id"],
    )
    op.create_index(
        "ix_workflow_questions_position",
        "interview_workflow_questions",
        ["workflow_id", "position"],
    )


def downgrade() -> None:
    op.drop_table("interview_workflow_questions")
    op.drop_table("interview_workflows")
