"""initial_tables

Revision ID: 82f27c891782
Revises: 
Create Date: 2025-05-29 08:46:57.336988

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '82f27c891782'
down_revision: Union[str, None] = None
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.create_table('accounting_entries',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('model', sa.String(), nullable=False),
    sa.Column('prompt_tokens', sa.Integer(), nullable=True),
    sa.Column('completion_tokens', sa.Integer(), nullable=True),
    sa.Column('total_tokens', sa.Integer(), nullable=True),
    sa.Column('local_prompt_tokens', sa.Integer(), nullable=True),
    sa.Column('local_completion_tokens', sa.Integer(), nullable=True),
    sa.Column('local_total_tokens', sa.Integer(), nullable=True),
    sa.Column('project', sa.String(), nullable=True),
    sa.Column('cost', sa.Float(), nullable=False),
    sa.Column('execution_time', sa.Float(), nullable=False),
    sa.Column('caller_name', sa.String(), nullable=True),
    sa.Column('username', sa.String(), nullable=True),
    sa.Column('cached_tokens', sa.Integer(), nullable=False),
    sa.Column('reasoning_tokens', sa.Integer(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('audit_log_entries',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('app_name', sa.String(), nullable=False),
    sa.Column('user_name', sa.String(), nullable=False),
    sa.Column('model', sa.String(), nullable=False),
    sa.Column('prompt_text', sa.String(), nullable=True),
    sa.Column('response_text', sa.String(), nullable=True),
    sa.Column('remote_completion_id', sa.String(), nullable=True),
    sa.Column('project', sa.String(), nullable=True),
    sa.Column('log_type', sa.String(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('usage_limits',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('scope', sa.String(), nullable=False),
    sa.Column('limit_type', sa.String(), nullable=False),
    sa.Column('max_value', sa.Float(), nullable=False),
    sa.Column('interval_unit', sa.String(), nullable=False),
    sa.Column('interval_value', sa.Integer(), nullable=False),
    sa.Column('model', sa.String(), nullable=True),
    sa.Column('username', sa.String(), nullable=True),
    sa.Column('caller_name', sa.String(), nullable=True),
    sa.Column('project_name', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('scope', 'limit_type', 'model', 'username', 'caller_name', 'project_name', name='_unique_limit_constraint')
    )
    with op.batch_alter_table('usage_limits', schema=None) as batch_op:
        batch_op.create_index('ix_usage_limits_project_name', ['project_name'], unique=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('usage_limits', schema=None) as batch_op:
        batch_op.drop_index('ix_usage_limits_project_name')

    op.drop_table('usage_limits')
    op.drop_table('audit_log_entries')
    op.drop_table('accounting_entries')
    # ### end Alembic commands ###
