"""payment method instructions currency, sale fulfillment + attachments

Revision ID: 713ef8b8ce97
Revises: 4332b67bf735
Create Date: 2026-05-09 09:13:06.954137

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '713ef8b8ce97'
down_revision = '4332b67bf735'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('sale_attachments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('sale_id', sa.Integer(), nullable=False),
    sa.Column('kind', sa.Enum('PAYMENT_PROOF', 'DELIVERY_PROOF', name='attachmentkind', native_enum=False, length=20), nullable=False),
    sa.Column('file_url', sa.String(length=255), nullable=False),
    sa.Column('filename', sa.String(length=180), nullable=True),
    sa.Column('mime_type', sa.String(length=80), nullable=True),
    sa.Column('note', sa.Text(), nullable=True),
    sa.Column('uploaded_by_user_id', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['sale_id'], ['sales.id'], ),
    sa.ForeignKeyConstraint(['uploaded_by_user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('sale_attachments', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_sale_attachments_created_at'), ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_sale_attachments_kind'), ['kind'], unique=False)
        batch_op.create_index(batch_op.f('ix_sale_attachments_sale_id'), ['sale_id'], unique=False)
        batch_op.create_index(batch_op.f('ix_sale_attachments_uploaded_by_user_id'), ['uploaded_by_user_id'], unique=False)

    with op.batch_alter_table('payment_methods', schema=None) as batch_op:
        batch_op.add_column(sa.Column('currency_id', sa.Integer(), nullable=True))
        batch_op.add_column(sa.Column('instructions', sa.Text(), nullable=True))
        batch_op.add_column(sa.Column('requires_proof', sa.Boolean(), nullable=False, server_default=sa.false()))
        batch_op.create_index(batch_op.f('ix_payment_methods_currency_id'), ['currency_id'], unique=False)
        batch_op.create_foreign_key(None, 'currencies', ['currency_id'], ['id'])

    with op.batch_alter_table('sales', schema=None) as batch_op:
        batch_op.add_column(sa.Column('fulfillment_status', sa.Enum('PENDING', 'IN_PROGRESS', 'COMPLETED', name='fulfillmentstatus', native_enum=False, length=20), nullable=False, server_default='PENDING'))
        batch_op.add_column(sa.Column('payment_currency', sa.String(length=8), nullable=True))
        batch_op.add_column(sa.Column('payment_exchange_rate', sa.Numeric(precision=18, scale=6), nullable=True))
        batch_op.add_column(sa.Column('payment_total', sa.Numeric(precision=14, scale=2), nullable=True))
        batch_op.create_index(batch_op.f('ix_sales_fulfillment_status'), ['fulfillment_status'], unique=False)

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('sales', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_sales_fulfillment_status'))
        batch_op.drop_column('payment_total')
        batch_op.drop_column('payment_exchange_rate')
        batch_op.drop_column('payment_currency')
        batch_op.drop_column('fulfillment_status')

    with op.batch_alter_table('payment_methods', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.drop_index(batch_op.f('ix_payment_methods_currency_id'))
        batch_op.drop_column('requires_proof')
        batch_op.drop_column('instructions')
        batch_op.drop_column('currency_id')

    with op.batch_alter_table('sale_attachments', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_sale_attachments_uploaded_by_user_id'))
        batch_op.drop_index(batch_op.f('ix_sale_attachments_sale_id'))
        batch_op.drop_index(batch_op.f('ix_sale_attachments_kind'))
        batch_op.drop_index(batch_op.f('ix_sale_attachments_created_at'))

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