# Generated by Django 4.2.23 on 2025-07-20 16:23

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

from .. import migration_utils as mig_utils


def add_productionconfig_simulation_item_index(apps, schema_editor):
    mig_utils.add_index_if_missing(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="ProductionConfig",
        index_name="indy_hub_pr_simulat_700399_idx",
        fields=("simulation", "item_type_id"),
    )


def remove_productionconfig_simulation_item_index(apps, schema_editor):
    mig_utils.remove_index_if_exists(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="ProductionConfig",
        index_name="indy_hub_pr_simulat_700399_idx",
        fields=("simulation", "item_type_id"),
    )


def add_customprice_user_item_index(apps, schema_editor):
    mig_utils.add_index_if_missing(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="CustomPrice",
        index_name="indy_hub_cu_user_id_7e8b65_idx",
        fields=("user", "item_type_id"),
    )


def remove_customprice_user_item_index(apps, schema_editor):
    mig_utils.remove_index_if_exists(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="CustomPrice",
        index_name="indy_hub_cu_user_id_7e8b65_idx",
        fields=("user", "item_type_id"),
    )


def add_customprice_simulation_item_index(apps, schema_editor):
    mig_utils.add_index_if_missing(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="CustomPrice",
        index_name="indy_hub_cu_simulat_e46670_idx",
        fields=("simulation", "item_type_id"),
    )


def remove_customprice_simulation_item_index(apps, schema_editor):
    mig_utils.remove_index_if_exists(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="CustomPrice",
        index_name="indy_hub_cu_simulat_e46670_idx",
        fields=("simulation", "item_type_id"),
    )


def add_blueprintefficiency_user_index(apps, schema_editor):
    mig_utils.add_index_if_missing(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="BlueprintEfficiency",
        index_name="indy_hub_bl_user_id_c3e8ee_idx",
        fields=("user", "blueprint_type_id"),
    )


def remove_blueprintefficiency_user_index(apps, schema_editor):
    mig_utils.remove_index_if_exists(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="BlueprintEfficiency",
        index_name="indy_hub_bl_user_id_c3e8ee_idx",
        fields=("user", "blueprint_type_id"),
    )


def add_blueprintefficiency_simulation_index(apps, schema_editor):
    mig_utils.add_index_if_missing(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="BlueprintEfficiency",
        index_name="indy_hub_bl_simulat_31616a_idx",
        fields=("simulation", "blueprint_type_id"),
    )


def remove_blueprintefficiency_simulation_index(apps, schema_editor):
    mig_utils.remove_index_if_exists(
        apps,
        schema_editor,
        app_label="indy_hub",
        model_name="BlueprintEfficiency",
        index_name="indy_hub_bl_simulat_31616a_idx",
        fields=("simulation", "blueprint_type_id"),
    )


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("indy_hub", "0017_add_production_simulation"),
    ]

    operations = [
        migrations.CreateModel(
            name="BlueprintEfficiency",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("blueprint_type_id", models.BigIntegerField()),
                (
                    "material_efficiency",
                    models.IntegerField(
                        default=0,
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(10),
                        ],
                    ),
                ),
                (
                    "time_efficiency",
                    models.IntegerField(
                        default=0,
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(20),
                        ],
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="CustomPrice",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("item_type_id", models.BigIntegerField()),
                (
                    "unit_price",
                    models.DecimalField(decimal_places=2, default=0, max_digits=20),
                ),
                ("is_sale_price", models.BooleanField(default=False)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "default_permissions": (),
            },
        ),
        migrations.AlterUniqueTogether(
            name="productionconfig",
            unique_together=set(),
        ),
        migrations.AddField(
            model_name="productionconfig",
            name="simulation",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="production_configs",
                to="indy_hub.productionsimulation",
            ),
        ),
        migrations.AddField(
            model_name="productionsimulation",
            name="active_tab",
            field=models.CharField(default="materials", max_length=50),
        ),
        migrations.AddField(
            model_name="productionsimulation",
            name="estimated_profit",
            field=models.DecimalField(decimal_places=2, default=0, max_digits=20),
        ),
        migrations.AddField(
            model_name="productionsimulation",
            name="estimated_revenue",
            field=models.DecimalField(decimal_places=2, default=0, max_digits=20),
        ),
        migrations.AlterUniqueTogether(
            name="productionconfig",
            unique_together={("simulation", "item_type_id")},
        ),
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.AddIndex(
                    model_name="productionconfig",
                    index=models.Index(
                        fields=["simulation", "item_type_id"],
                        name="indy_hub_pr_simulat_700399_idx",
                    ),
                )
            ],
            database_operations=[
                migrations.RunPython(
                    add_productionconfig_simulation_item_index,
                    reverse_code=remove_productionconfig_simulation_item_index,
                )
            ],
        ),
        migrations.AddField(
            model_name="customprice",
            name="simulation",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="custom_prices",
                to="indy_hub.productionsimulation",
            ),
        ),
        migrations.AddField(
            model_name="customprice",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.AddField(
            model_name="blueprintefficiency",
            name="simulation",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="blueprint_efficiencies",
                to="indy_hub.productionsimulation",
            ),
        ),
        migrations.AddField(
            model_name="blueprintefficiency",
            name="user",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
            ),
        ),
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.AddIndex(
                    model_name="customprice",
                    index=models.Index(
                        fields=["user", "item_type_id"],
                        name="indy_hub_cu_user_id_7e8b65_idx",
                    ),
                )
            ],
            database_operations=[
                migrations.RunPython(
                    add_customprice_user_item_index,
                    reverse_code=remove_customprice_user_item_index,
                )
            ],
        ),
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.AddIndex(
                    model_name="customprice",
                    index=models.Index(
                        fields=["simulation", "item_type_id"],
                        name="indy_hub_cu_simulat_e46670_idx",
                    ),
                )
            ],
            database_operations=[
                migrations.RunPython(
                    add_customprice_simulation_item_index,
                    reverse_code=remove_customprice_simulation_item_index,
                )
            ],
        ),
        migrations.AlterUniqueTogether(
            name="customprice",
            unique_together={("simulation", "item_type_id")},
        ),
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.AddIndex(
                    model_name="blueprintefficiency",
                    index=models.Index(
                        fields=["user", "blueprint_type_id"],
                        name="indy_hub_bl_user_id_c3e8ee_idx",
                    ),
                )
            ],
            database_operations=[
                migrations.RunPython(
                    add_blueprintefficiency_user_index,
                    reverse_code=remove_blueprintefficiency_user_index,
                )
            ],
        ),
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.AddIndex(
                    model_name="blueprintefficiency",
                    index=models.Index(
                        fields=["simulation", "blueprint_type_id"],
                        name="indy_hub_bl_simulat_31616a_idx",
                    ),
                )
            ],
            database_operations=[
                migrations.RunPython(
                    add_blueprintefficiency_simulation_index,
                    reverse_code=remove_blueprintefficiency_simulation_index,
                )
            ],
        ),
        migrations.AlterUniqueTogether(
            name="blueprintefficiency",
            unique_together={("simulation", "blueprint_type_id")},
        ),
    ]
