# Generated by Django 5.2.17 on 2026-10-01 09:05

import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='LedgerTransaction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('reference', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('kind', models.CharField(max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('memo', models.CharField(blank=True, max_length=200)),
            ],
        ),
        migrations.CreateModel(
            name='AuditLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action', models.CharField(max_length=80)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('details', models.CharField(blank=True, max_length=250)),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='Transfer',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('asset', models.CharField(choices=[('TZS', 'Tanzanian Shilling (simulated)'), ('USDT', 'USDT (simulated)')], max_length=4)),
                ('amount_minor', models.PositiveBigIntegerField()),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('recipient', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='received_transfers', to=settings.AUTH_USER_MODEL)),
                ('sender', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='sent_transfers', to=settings.AUTH_USER_MODEL)),
                ('transaction', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, to='wallets.ledgertransaction')),
            ],
        ),
        migrations.CreateModel(
            name='Wallet',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('asset', models.CharField(choices=[('TZS', 'Tanzanian Shilling (simulated)'), ('USDT', 'USDT (simulated)')], max_length=4)),
                ('balance_minor', models.BigIntegerField(default=0)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='wallets', to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='LedgerEntry',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('direction', models.CharField(choices=[('debit', 'Debit'), ('credit', 'Credit')], max_length=6)),
                ('amount_minor', models.PositiveBigIntegerField()),
                ('transaction', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='entries', to='wallets.ledgertransaction')),
                ('wallet', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='entries', to='wallets.wallet')),
            ],
        ),
        migrations.CreateModel(
            name='Withdrawal',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('channel', models.CharField(choices=[('bank', 'Bank (simulated)'), ('blockchain', 'Blockchain (simulated)')], max_length=12)),
                ('destination', models.CharField(max_length=180)),
                ('amount_minor', models.PositiveBigIntegerField()),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('completed', 'Completed (simulated)'), ('failed', 'Failed')], default='pending', max_length=12)),
                ('reference', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
                ('wallet', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='wallets.wallet')),
            ],
        ),
        migrations.CreateModel(
            name='Terminal',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('terminal_id', models.CharField(default='TERM-000001', max_length=64, unique=True)),
                ('protocol', models.CharField(choices=[('HTTPS', 'HTTPS'), ('HTTP', 'HTTP (local testing only)'), ('TCP', 'TCP'), ('OTHER', 'Other')], default='HTTPS', max_length=10)),
                ('ip_address', models.GenericIPAddressField(default='127.0.0.1')),
                ('dns_name', models.CharField(default='localhost', max_length=253)),
                ('machine_os', models.CharField(default='Windows 11', max_length=100)),
                ('port', models.PositiveSmallIntegerField(default=8000)),
                ('min_receiving_usd', models.DecimalField(decimal_places=2, default='10.00', max_digits=14)),
                ('max_receiving_usd', models.DecimalField(decimal_places=2, default='1000000.00', max_digits=14)),
                ('status', models.CharField(choices=[('active', 'Active'), ('suspended', 'Suspended'), ('offline', 'Offline')], default='active', max_length=12)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('last_seen_at', models.DateTimeField(blank=True, null=True)),
                ('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='terminals', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['terminal_id'],
                'constraints': [models.CheckConstraint(condition=models.Q(('port__gte', 1), ('port__lte', 65535)), name='terminal_port_valid'), models.CheckConstraint(condition=models.Q(('min_receiving_usd__gte', 0)), name='terminal_min_usd_nonnegative'), models.CheckConstraint(condition=models.Q(('max_receiving_usd__gte', 0)), name='terminal_max_usd_nonnegative'), models.CheckConstraint(condition=models.Q(('max_receiving_usd__gte', models.F('min_receiving_usd'))), name='terminal_max_gte_min')],
            },
        ),
        migrations.AddConstraint(
            model_name='wallet',
            constraint=models.UniqueConstraint(fields=('user', 'asset'), name='unique_user_asset_wallet'),
        ),
        migrations.AddConstraint(
            model_name='wallet',
            constraint=models.CheckConstraint(condition=models.Q(('balance_minor__gte', 0)), name='wallet_balance_nonnegative'),
        ),
        migrations.AddConstraint(
            model_name='ledgerentry',
            constraint=models.CheckConstraint(condition=models.Q(('amount_minor__gt', 0)), name='ledger_amount_positive'),
        ),
    ]
