"""add_benefits_tables_and_benefit_to_payroll_run_items

Revision ID: 9867676a4662
Revises: 5ecdfa3c94b6
Create Date: 2026-03-16 11:57:10.856557

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


revision: str = '9867676a4662'
down_revision: Union[str, None] = '5ecdfa3c94b6'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('benefits',
    sa.Column('id', sa.String(), nullable=False),
    sa.Column('employee_id', sa.String(), nullable=False),
    sa.Column('benefit_date', sa.Date(), nullable=False),
    sa.Column('total_amount', sa.Integer(), nullable=False),
    sa.Column('monthly_benefit', sa.Integer(), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('remaining_balance', sa.Integer(), nullable=False),
    sa.Column('status', sa.String(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['employee_id'], ['employees.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('benefit_transactions',
    sa.Column('id', sa.String(), nullable=False),
    sa.Column('benefit_id', sa.String(), nullable=False),
    sa.Column('employee_id', sa.String(), nullable=False),
    sa.Column('transaction_date', sa.Date(), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('debit', sa.Integer(), nullable=False),
    sa.Column('credit', sa.Integer(), nullable=False),
    sa.Column('balance', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['benefit_id'], ['benefits.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['employee_id'], ['employees.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('payroll_run_items', sa.Column('benefit', sa.Integer(), nullable=False, server_default='0'))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('payroll_run_items', 'benefit')
    op.drop_table('benefit_transactions')
    op.drop_table('benefits')
    # ### end Alembic commands ###
