"""add tree_type and intake_form to trees

Revision ID: 035
Revises: 034
Create Date: 2026-02-14

Adds tree_type (troubleshooting/procedural) and intake_form (JSONB) columns to trees table.
"""
from typing import Sequence, Union

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


# revision identifiers, used by Alembic.
revision: str = '035'
down_revision: Union[str, None] = '034'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column('trees', sa.Column(
        'tree_type',
        sa.String(20),
        nullable=False,
        server_default='troubleshooting',
    ))
    op.add_column('trees', sa.Column(
        'intake_form',
        JSONB(),
        nullable=True,
    ))
    op.create_check_constraint(
        'ck_trees_tree_type',
        'trees',
        "tree_type IN ('troubleshooting', 'procedural')",
    )
    op.create_index('ix_trees_tree_type', 'trees', ['tree_type'])


def downgrade() -> None:
    op.drop_index('ix_trees_tree_type', table_name='trees')
    op.drop_constraint('ck_trees_tree_type', 'trees', type_='check')
    op.drop_column('trees', 'intake_form')
    op.drop_column('trees', 'tree_type')
