"""add candidate_resume_profiles table

Revision ID: a8b9c0d1e2f3
Revises: f7a8b9c0d1e2
Create Date: 2026-11-03

"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "a8b9c0d1e2f3"
down_revision: Union[str, Sequence[str], None] = "f7a8b9c0d1e2"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "candidate_resume_profiles",
        sa.Column("profile_id", sa.String(length=64), primary_key=True),
        sa.Column("candidate_id", sa.String(length=128), nullable=False),
        sa.Column("company_id", sa.String(length=128), nullable=True),
        sa.Column("resume_version", sa.Integer(), nullable=False),
        sa.Column("content_hash", sa.String(length=64), nullable=False),
        sa.Column("source_url", sa.String(length=2048), nullable=True),
        sa.Column("filename", sa.String(length=512), nullable=True),
        sa.Column("document_type", sa.String(length=32), nullable=True),
        sa.Column("raw_text", sa.Text(), nullable=True),
        sa.Column("structured", sa.JSON(), nullable=False),
        sa.Column("blocks", sa.JSON(), 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),
        sa.UniqueConstraint(
            "candidate_id",
            "content_hash",
            name="uq_resume_profile_candidate_hash",
        ),
    )
    op.create_index(
        "ix_candidate_resume_profiles_candidate_id",
        "candidate_resume_profiles",
        ["candidate_id"],
    )
    op.create_index(
        "ix_candidate_resume_profiles_company_id",
        "candidate_resume_profiles",
        ["company_id"],
    )
    op.create_index(
        "ix_candidate_resume_profiles_content_hash",
        "candidate_resume_profiles",
        ["content_hash"],
    )
    op.create_index(
        "ix_resume_profiles_candidate_version",
        "candidate_resume_profiles",
        ["candidate_id", "resume_version"],
    )
    op.create_index(
        "ix_resume_profiles_updated",
        "candidate_resume_profiles",
        ["updated_at"],
    )


def downgrade() -> None:
    op.drop_index("ix_resume_profiles_updated", table_name="candidate_resume_profiles")
    op.drop_index(
        "ix_resume_profiles_candidate_version", table_name="candidate_resume_profiles"
    )
    op.drop_index(
        "ix_candidate_resume_profiles_content_hash",
        table_name="candidate_resume_profiles",
    )
    op.drop_index(
        "ix_candidate_resume_profiles_company_id",
        table_name="candidate_resume_profiles",
    )
    op.drop_index(
        "ix_candidate_resume_profiles_candidate_id",
        table_name="candidate_resume_profiles",
    )
    op.drop_table("candidate_resume_profiles")
