"""
Migration: Add DeveloperPayment model
Tracks all payments made from this system to the developer (PhinTech Solutions Company Ltd).
"""

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

    dependencies = [
        ('payments', '0003_sasapay_models'),
        ('users', '0024_enhanced_permissions_models'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='DeveloperPayment',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('amount', models.DecimalField(decimal_places=2, help_text='Amount in KES', max_digits=12)),
                ('payment_type', models.CharField(
                    choices=[
                        ('maintenance', 'System Maintenance Fee'),
                        ('license', 'Software License Fee'),
                        ('support', 'Support & Consultation'),
                        ('upgrade', 'System Upgrade'),
                        ('custom', 'Custom Development'),
                        ('other', 'Other'),
                    ],
                    default='maintenance',
                    max_length=20,
                )),
                ('description', models.TextField(help_text='Purpose / description of this payment')),
                ('reference', models.CharField(
                    help_text='Unique reference for this payment (auto-generated)',
                    max_length=100,
                    unique=True,
                )),
                ('payer_phone', models.CharField(
                    help_text='M-Pesa phone number used to complete the payment (company phone)',
                    max_length=17,
                )),
                ('status', models.CharField(
                    choices=[
                        ('pending', 'Pending'),
                        ('processing', 'Processing'),
                        ('completed', 'Completed'),
                        ('failed', 'Failed'),
                        ('cancelled', 'Cancelled'),
                    ],
                    default='pending',
                    max_length=20,
                )),
                ('lipia_checkout_id', models.CharField(
                    blank=True,
                    help_text='Checkout/request ID returned by LipiaOnline',
                    max_length=200,
                    null=True,
                )),
                ('lipia_transaction_id', models.CharField(
                    blank=True,
                    help_text='Final transaction ID from LipiaOnline / M-Pesa',
                    max_length=200,
                    null=True,
                )),
                ('mpesa_receipt', models.CharField(
                    blank=True,
                    help_text='M-Pesa confirmation code (e.g. QHX7XXXXXX)',
                    max_length=100,
                    null=True,
                )),
                ('raw_initiation_response', models.JSONField(
                    blank=True,
                    help_text='Raw JSON response from LipiaOnline when payment was initiated',
                    null=True,
                )),
                ('raw_callback_data', models.JSONField(
                    blank=True,
                    help_text='Raw JSON callback/webhook data received from LipiaOnline',
                    null=True,
                )),
                ('admin_notes', models.TextField(blank=True, help_text='Internal notes about this payment', null=True)),
                ('failure_reason', models.TextField(blank=True, help_text='Reason for failure if applicable', null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('completed_at', models.DateTimeField(blank=True, null=True)),
                ('initiated_by', models.ForeignKey(
                    blank=True,
                    help_text='Staff member who initiated this payment',
                    null=True,
                    on_delete=django.db.models.deletion.SET_NULL,
                    related_name='developer_payments_initiated',
                    to=settings.AUTH_USER_MODEL,
                )),
            ],
            options={
                'verbose_name': 'Developer Payment',
                'verbose_name_plural': 'Developer Payments',
                'db_table': 'developer_payments',
                'ordering': ['-created_at'],
            },
        ),
    ]
