"""drop activity and activity_percentage_queue tables

Revision ID: g0123hi4567
Revises: f9012gh3456
Create Date: 2025-01-17 14:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


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


def upgrade() -> None:
    """
    Drop activity and activity_percentage_queue tables (unused)
    - activity: ActivityEntity is created but never saved to database
    - activity_percentage_queue: Replaced by universal db_write_queue system
    """
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    tables = inspector.get_table_names()
    
    if 'activity' in tables:
        op.drop_table('activity')
        print("Dropped 'activity' table")
    
    if 'activity_percentage_queue' in tables:
        op.drop_table('activity_percentage_queue')
        print("Dropped 'activity_percentage_queue' table")


def downgrade() -> None:
    """
    Recreate activity and activity_percentage_queue tables (if needed for rollback)
    """
    # Recreate activity table
    op.create_table('activity',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('keyboard_count', sa.Integer(), nullable=True),
        sa.Column('keyboard_activity', sa.JSON(), nullable=True),
        sa.Column('mouse_click_count', sa.Integer(), nullable=True),
        sa.Column('mouse_activity', sa.JSON(), nullable=True),
        sa.Column('timestamp', sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint('id')
    )
    
    # Recreate activity_percentage_queue table
    op.create_table('activity_percentage_queue',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('start', sa.DateTime(), nullable=True),
        sa.Column('stop', sa.DateTime(), nullable=True),
        sa.Column('keyboard', sa.Float(), nullable=True),
        sa.Column('mouse', sa.Float(), nullable=True),
        sa.Column('average', sa.Float(), nullable=True),
        sa.Column('minute', sa.Integer(), nullable=True),
        sa.Column('processed', sa.Boolean(), nullable=True),
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('processed_at', sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint('id')
    )

