# Generated by Django 5.2.11 on 2026-04-12 19:00

import django.db.models.deletion
import django.utils.timezone
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('core', '0004_shipper_7_10_billing_engagement_push'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Payment',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('method', models.CharField(choices=[('WALLET', 'Wallet'), ('CARD', 'Card'), ('CASH', 'Cash'), ('CREDIT', 'Credit terms')], max_length=20)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=14)),
                ('currency', models.CharField(default='USD', max_length=3)),
                ('status', models.CharField(choices=[('PENDING', 'Pending'), ('REQUIRES_ACTION', 'Requires client action'), ('PROCESSING', 'Processing'), ('CAPTURED', 'Captured'), ('FAILED', 'Failed'), ('REFUNDED', 'Refunded'), ('PENDING_COD', 'Cash on delivery pending collection')], default='PENDING', max_length=30)),
                ('provider_ref', models.CharField(blank=True, max_length=255)),
                ('idempotency_key', models.CharField(blank=True, max_length=128)),
                ('metadata', models.JSONField(blank=True, default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('payee', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments_received', to=settings.AUTH_USER_MODEL)),
                ('payer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments_made', to=settings.AUTH_USER_MODEL)),
                ('trip', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='core.trip')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Invoice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('number', models.CharField(max_length=32, unique=True)),
                ('line_items', models.JSONField(default=list)),
                ('tax', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('total', models.DecimalField(decimal_places=2, max_digits=14)),
                ('status', models.CharField(choices=[('DRAFT', 'Draft'), ('ISSUED', 'Issued'), ('PAID', 'Paid'), ('VOID', 'Void')], default='ISSUED', max_length=20)),
                ('due_date', models.DateField(blank=True, null=True)),
                ('issued_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('shipper', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invoices', to=settings.AUTH_USER_MODEL)),
                ('trip', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invoices', to='core.trip')),
                ('payment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoices', to='billing.payment')),
            ],
            options={
                'ordering': ['-issued_at'],
            },
        ),
        migrations.CreateModel(
            name='WalletAccount',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('balance', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=14)),
                ('currency', models.CharField(default='USD', max_length=3)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='wallet_account', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Wallet account',
            },
        ),
        migrations.CreateModel(
            name='WithdrawalRequest',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('amount', models.DecimalField(decimal_places=2, max_digits=14)),
                ('currency', models.CharField(default='USD', max_length=3)),
                ('status', models.CharField(choices=[('PENDING', 'Pending'), ('APPROVED', 'Approved'), ('REJECTED', 'Rejected'), ('PAID', 'Paid')], default='PENDING', max_length=20)),
                ('note', models.CharField(blank=True, max_length=500)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='withdrawal_requests', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='LedgerEntry',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('amount', models.DecimalField(decimal_places=2, help_text='Signed: positive adds to wallet balance, negative subtracts.', max_digits=14)),
                ('entry_type', models.CharField(choices=[('WALLET_DEBIT_PAYMENT', 'Wallet debit (shipment payment)'), ('WALLET_CREDIT_EARNING', 'Wallet credit (trip earning)'), ('WALLET_CREDIT_TOPUP', 'Wallet credit (top-up)'), ('CREDIT_EARNING', 'Credit terms earning (transporter credit)'), ('WITHDRAWAL_DEBIT', 'Withdrawal debit'), ('ADJUSTMENT', 'Manual adjustment')], max_length=40)),
                ('idempotency_key', models.CharField(blank=True, db_index=True, max_length=128)),
                ('note', models.CharField(blank=True, max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('trip', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='ledger_entries', to='core.trip')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ledger_entries', to=settings.AUTH_USER_MODEL)),
                ('payment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='ledger_entries', to='billing.payment')),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['user', '-created_at'], name='billing_led_user_id_ab3f37_idx')],
            },
        ),
    ]
