"""Improvements to the Entitlements domain in context of LicensePeriod

Revision ID: 9f4ea4aff2f5
Revises: ef0aaf00f26d
Create Date: 2025-05-16 13:51:29.338916

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '9f4ea4aff2f5'
down_revision = 'ef0aaf00f26d'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('license_change_log',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('license_id', sa.Integer(), nullable=False),
    sa.Column('changed_at', sa.DateTime(), nullable=False),
    sa.Column('field_name', sa.String(length=100), nullable=False),
    sa.Column('old_value', sa.String(length=255), nullable=True),
    sa.Column('new_value', sa.String(length=255), nullable=False),
    sa.Column('reason', sa.Text(), nullable=True),
    sa.Column('created_by', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['created_by'], ['public.user.id'], ),
    sa.ForeignKeyConstraint(['license_id'], ['public.license.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='public'
    )
    with op.batch_alter_table('invoice', schema=None) as batch_op:
        batch_op.add_column(sa.Column('tenant_id', sa.Integer(), nullable=False))
        batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public')

    with op.batch_alter_table('license_period', schema=None) as batch_op:
        batch_op.add_column(sa.Column('tenant_id', sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('currency', sa.String(length=20), nullable=False))
        batch_op.add_column(sa.Column('basic_fee', sa.Float(), nullable=False))
        batch_op.add_column(sa.Column('max_storage_mb', sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('additional_storage_price', sa.Float(), nullable=False))
        batch_op.add_column(sa.Column('additional_storage_bucket', sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('included_embedding_mb', sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('additional_embedding_price', sa.Numeric(precision=10, scale=4), nullable=False))
        batch_op.add_column(sa.Column('additional_embedding_bucket', sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('included_interaction_tokens', sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('additional_interaction_token_price', sa.Numeric(precision=10, scale=4), nullable=False))
        batch_op.add_column(sa.Column('additional_interaction_bucket', sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('additional_storage_allowed', sa.Boolean(), nullable=False))
        batch_op.add_column(sa.Column('additional_embedding_allowed', sa.Boolean(), nullable=False))
        batch_op.add_column(sa.Column('additional_interaction_allowed', sa.Boolean(), nullable=False))
        batch_op.drop_constraint('license_period_license_id_fkey', type_='foreignkey')
        batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public')

    with op.batch_alter_table('payment', schema=None) as batch_op:
        batch_op.add_column(sa.Column('tenant_id', sa.Integer(), nullable=False))
        batch_op.create_foreign_key(None, 'tenant', ['tenant_id'], ['id'], referent_schema='public')

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###
