# Generated by Django for IGNY8 Billing App
# Date: December 4, 2025

from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='CreditTransaction',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('transaction_type', models.CharField(
                    choices=[
                        ('purchase', 'Purchase'),
                        ('deduction', 'Deduction'),
                        ('refund', 'Refund'),
                        ('grant', 'Grant'),
                        ('adjustment', 'Manual Adjustment'),
                    ],
                    max_length=20
                )),
                ('amount', models.IntegerField(help_text='Positive for additions, negative for deductions')),
                ('balance_after', models.IntegerField(help_text='Account balance after this transaction')),
                ('description', models.CharField(max_length=255)),
                ('metadata', models.JSONField(default=dict, help_text='Additional transaction details')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('account', models.ForeignKey(
                    on_delete=django.db.models.deletion.CASCADE,
                    related_name='credit_transactions',
                    to=settings.AUTH_USER_MODEL
                )),
            ],
            options={
                'verbose_name': 'Credit Transaction',
                'verbose_name_plural': 'Credit Transactions',
                'db_table': 'igny8_credit_transactions',
                'ordering': ['-created_at'],
                'indexes': [
                    models.Index(fields=['account', '-created_at'], name='idx_credit_txn_account_date'),
                    models.Index(fields=['transaction_type'], name='idx_credit_txn_type'),
                ],
            },
        ),
        migrations.CreateModel(
            name='CreditUsageLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('operation_type', models.CharField(
                    choices=[
                        ('clustering', 'Clustering'),
                        ('idea_generation', 'Idea Generation'),
                        ('content_generation', 'Content Generation'),
                        ('image_generation', 'Image Generation'),
                        ('image_prompt_extraction', 'Image Prompt Extraction'),
                        ('taxonomy_generation', 'Taxonomy Generation'),
                        ('content_rewrite', 'Content Rewrite'),
                        ('keyword_research', 'Keyword Research'),
                        ('site_page_generation', 'Site Page Generation'),
                    ],
                    max_length=50
                )),
                ('credits_used', models.IntegerField()),
                ('cost_usd', models.DecimalField(decimal_places=2, max_digits=10, null=True, blank=True)),
                ('model_used', models.CharField(max_length=100, blank=True)),
                ('tokens_input', models.IntegerField(null=True, blank=True)),
                ('tokens_output', models.IntegerField(null=True, blank=True)),
                ('related_object_type', models.CharField(max_length=50, blank=True)),
                ('related_object_id', models.IntegerField(null=True, blank=True)),
                ('metadata', models.JSONField(default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('account', models.ForeignKey(
                    on_delete=django.db.models.deletion.CASCADE,
                    related_name='credit_usage_logs',
                    to=settings.AUTH_USER_MODEL
                )),
            ],
            options={
                'verbose_name': 'Credit Usage Log',
                'verbose_name_plural': 'Credit Usage Logs',
                'db_table': 'igny8_credit_usage_logs',
                'ordering': ['-created_at'],
                'indexes': [
                    models.Index(fields=['account', '-created_at'], name='idx_credit_usage_account_date'),
                    models.Index(fields=['operation_type'], name='idx_credit_usage_operation'),
                ],
            },
        ),
    ]
