# Generated by Django 5.0.2 on 2025-09-10 06:06

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='Subscription',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('plan', models.CharField(choices=[('basic', 'Basic - KES 2,000/month'), ('standard', 'Standard - KES 5,000/month'), ('premium', 'Premium - KES 10,000/month')], max_length=20)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=10)),
                ('start_date', models.DateTimeField()),
                ('end_date', models.DateTimeField()),
                ('payment_status', models.CharField(choices=[('pending', 'Pending'), ('paid', 'Paid'), ('failed', 'Failed'), ('refunded', 'Refunded')], default='pending', max_length=20)),
                ('mpesa_reference', models.CharField(blank=True, max_length=50, null=True)),
                ('mpesa_transaction_id', models.CharField(blank=True, max_length=50, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
            ],
            options={
                'db_table': 'tenants_subscription',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='MpesaPayment',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('phone_number', models.CharField(max_length=15)),
                ('amount', models.DecimalField(decimal_places=2, max_digits=10)),
                ('merchant_request_id', models.CharField(blank=True, max_length=100)),
                ('checkout_request_id', models.CharField(blank=True, max_length=100)),
                ('mpesa_receipt_number', models.CharField(blank=True, max_length=50)),
                ('transaction_date', models.DateTimeField(blank=True, null=True)),
                ('status', models.CharField(choices=[('pending', 'Pending'), ('success', 'Success'), ('failed', 'Failed'), ('cancelled', 'Cancelled')], default='pending', max_length=20)),
                ('result_desc', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('subscription', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='mpesa_payments', to='tenants.subscription')),
            ],
            options={
                'db_table': 'tenants_mpesa_payment',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Tenant',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=255)),
                ('tenant_code', models.CharField(help_text='Unique code for tenant login (letters, numbers only, no spaces)', max_length=20, unique=True)),
                ('plan', models.CharField(choices=[('basic', 'Basic - KES 2,000/month'), ('standard', 'Standard - KES 5,000/month'), ('premium', 'Premium - KES 10,000/month')], default='basic', max_length=20)),
                ('status', models.CharField(choices=[('active', 'Active'), ('suspended', 'Suspended'), ('trial', 'Trial'), ('expired', 'Expired')], default='trial', max_length=20)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('trial_ends_at', models.DateTimeField(blank=True, null=True)),
                ('subscription_ends_at', models.DateTimeField(blank=True, null=True)),
                ('max_shops', models.IntegerField(default=1)),
                ('max_users', models.IntegerField(default=3)),
                ('contact_email', models.EmailField(max_length=254)),
                ('contact_phone', models.CharField(max_length=15)),
                ('address', models.TextField(blank=True)),
                ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owned_tenants', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'tenants_tenant',
            },
        ),
        migrations.AddField(
            model_name='subscription',
            name='tenant',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subscriptions', to='tenants.tenant'),
        ),
        migrations.CreateModel(
            name='TenantUser',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('role', models.CharField(choices=[('owner', 'Owner'), ('admin', 'Admin'), ('manager', 'Manager'), ('staff', 'Staff')], default='staff', max_length=20)),
                ('is_active', models.BooleanField(default=True)),
                ('joined_at', models.DateTimeField(auto_now_add=True)),
                ('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tenant_users', to='tenants.tenant')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tenant_memberships', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'db_table': 'tenants_tenant_user',
                'unique_together': {('tenant', 'user')},
            },
        ),
    ]
