# Generated by Django for IGNY8 Billing App
# Date: December 4, 2025
# Adds CreditCostConfig model for database-driven credit cost configuration

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


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('billing', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='CreditCostConfig',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('operation_type', models.CharField(
                    choices=[
                        ('clustering', 'Auto 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'),
                    ],
                    help_text='AI operation type',
                    max_length=50,
                    unique=True
                )),
                ('credits_cost', models.IntegerField(
                    help_text='Credits required for this operation',
                    validators=[django.core.validators.MinValueValidator(0)]
                )),
                ('unit', models.CharField(
                    choices=[
                        ('per_request', 'Per Request'),
                        ('per_100_words', 'Per 100 Words'),
                        ('per_image', 'Per Image'),
                        ('per_item', 'Per Item'),
                        ('per_keyword', 'Per Keyword'),
                    ],
                    default='per_request',
                    help_text='What the cost applies to',
                    max_length=50
                )),
                ('display_name', models.CharField(help_text='Human-readable name', max_length=100)),
                ('description', models.TextField(blank=True, help_text='What this operation does')),
                ('is_active', models.BooleanField(default=True, help_text='Enable/disable this operation')),
                ('previous_cost', models.IntegerField(
                    blank=True,
                    help_text='Cost before last update (for audit trail)',
                    null=True
                )),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('updated_by', models.ForeignKey(
                    blank=True,
                    help_text='Admin who last updated',
                    null=True,
                    on_delete=django.db.models.deletion.SET_NULL,
                    related_name='credit_cost_updates',
                    to=settings.AUTH_USER_MODEL
                )),
            ],
            options={
                'verbose_name': 'Credit Cost Configuration',
                'verbose_name_plural': 'Credit Cost Configurations',
                'db_table': 'igny8_credit_cost_config',
                'ordering': ['operation_type'],
            },
        ),
        migrations.AddIndex(
            model_name='creditcostconfig',
            index=models.Index(fields=['operation_type'], name='idx_credit_cost_op'),
        ),
        migrations.AddIndex(
            model_name='creditcostconfig',
            index=models.Index(fields=['is_active'], name='idx_credit_cost_active'),
        ),
    ]
