"""project stages, the feedback-complete marker, concept blurbs + thumbnails

Revision ID: b8d4f2a6c1e3
Revises: f7d2b09e5a13
Create Date: 2026-09-02

The board becomes the project's journey: a stage timeline in caddie's shape
(held here until the hub owns it), the client's "Feedback complete" round
marker, and a line + a picture per concept so the review stage reads at a
glance.
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = 'b8d4f2a6c1e3'
down_revision: Union[str, Sequence[str], None] = 'f7d2b09e5a13'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        'project_stages',
        sa.Column('id', sa.Integer(), primary_key=True),
        sa.Column('instance_id', sa.String(length=64), nullable=False),
        sa.Column('key', sa.String(length=64), nullable=False),
        sa.Column('position', sa.Integer(), nullable=False, server_default='0'),
        sa.Column('title', sa.String(length=200), nullable=False),
        sa.Column('body_md', sa.Text(), nullable=False, server_default=''),
        sa.Column('status', sa.String(length=16), nullable=False, server_default='planned'),
        sa.Column('client_visible', sa.Boolean(), nullable=False, server_default=sa.true()),
        sa.Column('started_at', sa.DateTime(timezone=True), nullable=True),
        sa.Column('closed_at', sa.DateTime(timezone=True), nullable=True),
        sa.UniqueConstraint('instance_id', 'key', name='uq_project_stages_instance_key'),
    )
    op.create_index('ix_project_stages_instance_id', 'project_stages', ['instance_id'])
    op.add_column('project_details',
                  sa.Column('feedback_completed_at', sa.DateTime(timezone=True), nullable=True))
    op.add_column('project_details',
                  sa.Column('feedback_completed_by', sa.String(length=64), nullable=True))
    op.add_column('options', sa.Column('blurb', sa.Text(), nullable=False, server_default=''))
    op.add_column('options', sa.Column('thumbnail_name', sa.String(length=64), nullable=True))


def downgrade() -> None:
    op.drop_column('options', 'thumbnail_name')
    op.drop_column('options', 'blurb')
    op.drop_column('project_details', 'feedback_completed_by')
    op.drop_column('project_details', 'feedback_completed_at')
    op.drop_index('ix_project_stages_instance_id', table_name='project_stages')
    op.drop_table('project_stages')
