"""add claim fields to item

Revision ID: 7f73c3196b99
Revises: d5f8a2e4c7b9
Create Date: 2025-06-28 16:11:49.500494

"""
from typing import Sequence, Union

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

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


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_apscheduler_jobs_next_run_time', table_name='apscheduler_jobs')
    op.drop_table('apscheduler_jobs')
    op.alter_column('categories', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('chore_assignments', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('chores', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('expense_splits', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('expenses', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('groups', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.add_column('items', sa.Column('claimed_by_user_id', sa.Integer(), nullable=True))
    op.add_column('items', sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True))
    op.add_column('items', sa.Column('claimed_at', sa.DateTime(timezone=True), nullable=True))
    op.alter_column('items', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.create_foreign_key(None, 'items', 'users', ['claimed_by_user_id'], ['id'])
    op.alter_column('lists', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('recurrence_patterns', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('time_entries', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('users', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('users', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('time_entries', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('recurrence_patterns', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('lists', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.drop_constraint(None, 'items', type_='foreignkey')
    op.alter_column('items', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.drop_column('items', 'claimed_at')
    op.drop_column('items', 'completed_at')
    op.drop_column('items', 'claimed_by_user_id')
    op.alter_column('groups', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('expenses', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('expense_splits', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('chores', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('chore_assignments', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('categories', 'is_deleted',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.create_table('apscheduler_jobs',
    sa.Column('id', sa.VARCHAR(length=191), autoincrement=False, nullable=False),
    sa.Column('next_run_time', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('job_state', postgresql.BYTEA(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', name='apscheduler_jobs_pkey')
    )
    op.create_index('ix_apscheduler_jobs_next_run_time', 'apscheduler_jobs', ['next_run_time'], unique=False)
    # ### end Alembic commands ###
