"""add nomenclature tables

Revision ID: 3a653da79002
Revises: 1cfb423c6953
Create Date: 2025-12-13 00:28:05.719430+00:00

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel


# revision identifiers, used by Alembic.
revision: str = '3a653da79002'
down_revision: Union[str, None] = '1cfb423c6953'
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('local_suppliers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=200), nullable=False),
    sa.Column('fiscal_code', sqlmodel.sql.sqltypes.AutoString(length=50), nullable=True),
    sa.Column('address', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True),
    sa.Column('created_by', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('pending_oracle_sync', sa.Boolean(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('local_suppliers', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_local_suppliers_company_id'), ['company_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_local_suppliers_fiscal_code'), ['fiscal_code'], unique=False)

    op.create_table('synced_cash_registers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('oracle_id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
    sa.Column('account_code', sqlmodel.sql.sqltypes.AutoString(length=20), nullable=False),
    sa.Column('register_type', sqlmodel.sql.sqltypes.AutoString(length=10), nullable=False),
    sa.Column('synced_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('synced_cash_registers', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_synced_cash_registers_company_id'), ['company_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_synced_cash_registers_oracle_id'), ['oracle_id'], unique=False)

    op.create_table('synced_suppliers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('oracle_id', sa.Integer(), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=200), nullable=False),
    sa.Column('fiscal_code', sqlmodel.sql.sqltypes.AutoString(length=50), nullable=True),
    sa.Column('address', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True),
    sa.Column('synced_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('synced_suppliers', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_synced_suppliers_company_id'), ['company_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_synced_suppliers_fiscal_code'), ['fiscal_code'], unique=False)
        batch_op.create_index(batch_op.f('ix_synced_suppliers_oracle_id'), ['oracle_id'], unique=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('synced_suppliers', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_synced_suppliers_oracle_id'))
        batch_op.drop_index(batch_op.f('ix_synced_suppliers_fiscal_code'))
        batch_op.drop_index(batch_op.f('ix_synced_suppliers_company_id'))

    op.drop_table('synced_suppliers')
    with op.batch_alter_table('synced_cash_registers', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_synced_cash_registers_oracle_id'))
        batch_op.drop_index(batch_op.f('ix_synced_cash_registers_company_id'))

    op.drop_table('synced_cash_registers')
    with op.batch_alter_table('local_suppliers', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_local_suppliers_fiscal_code'))
        batch_op.drop_index(batch_op.f('ix_local_suppliers_company_id'))

    op.drop_table('local_suppliers')
    # ### end Alembic commands ###
