"""add interview dialogue and analysis tables

Revision ID: c2d48b31ee30
Revises: de11b016b35a
Create Date: 2025-09-03 17:55:41.653125

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "c2d48b31ee30"
down_revision: str | Sequence[str] | None = "de11b016b35a"
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.drop_index(op.f("ix_interview_sessions_id"), table_name="interview_sessions")
    op.drop_table("interview_sessions")
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "interview_sessions",
        sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("resume_id", sa.INTEGER(), autoincrement=False, nullable=False),
        sa.Column(
            "room_name", sa.VARCHAR(length=255), autoincrement=False, nullable=False
        ),
        sa.Column(
            "status",
            postgresql.ENUM(
                "created", "active", "completed", "failed", name="interviewstatus"
            ),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column("transcript", sa.TEXT(), autoincrement=False, nullable=True),
        sa.Column("ai_feedback", sa.TEXT(), autoincrement=False, nullable=True),
        sa.Column(
            "started_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=False
        ),
        sa.Column(
            "completed_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=True
        ),
        sa.Column("ai_agent_pid", sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column(
            "ai_agent_status",
            sa.VARCHAR(),
            server_default=sa.text("'not_started'::character varying"),
            autoincrement=False,
            nullable=False,
        ),
        sa.ForeignKeyConstraint(
            ["resume_id"], ["resume.id"], name=op.f("interview_sessions_resume_id_fkey")
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("interview_sessions_pkey")),
        sa.UniqueConstraint(
            "room_name",
            name=op.f("interview_sessions_room_name_key"),
            postgresql_include=[],
            postgresql_nulls_not_distinct=False,
        ),
    )
    op.create_index(
        op.f("ix_interview_sessions_id"), "interview_sessions", ["id"], unique=False
    )
    # ### end Alembic commands ###
