# Generated by Django 5.2.8 on 2025-12-03 12:39

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


class Migration(migrations.Migration):

    dependencies = [
        ("common", "0039_emailthread_emailmessage"),
        ("contenttypes", "0002_remove_content_type_name"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("part", "0144_auto_20251203_1045")
    ]

    operations = [
         migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.CreateModel(
                    name="ParameterTemplate",
                    fields=[
                        (
                            "id",
                            models.AutoField(
                                auto_created=True,
                                primary_key=True,
                                serialize=False,
                                verbose_name="ID",
                            ),
                        ),
                        (
                            "metadata",
                            models.JSONField(
                                blank=True,
                                help_text="JSON metadata field, for use by external plugins",
                                null=True,
                                verbose_name="Plugin Metadata",
                            ),
                        ),
                        (
                            "name",
                            models.CharField(
                                help_text="Parameter Name",
                                max_length=100,
                                unique=True,
                                verbose_name="Name",
                            ),
                        ),
                        (
                            "units",
                            models.CharField(
                                blank=True,
                                help_text="Physical units for this parameter",
                                max_length=25,
                                validators=[InvenTree.validators.validate_physical_units],
                                verbose_name="Units",
                            ),
                        ),
                        (
                            "description",
                            models.CharField(
                                blank=True,
                                help_text="Parameter description",
                                max_length=250,
                                verbose_name="Description",
                            ),
                        ),
                        (
                            "checkbox",
                            models.BooleanField(
                                default=False,
                                help_text="Is this parameter a checkbox?",
                                verbose_name="Checkbox",
                            ),
                        ),
                        (
                            "choices",
                            models.CharField(
                                blank=True,
                                help_text="Valid choices for this parameter (comma-separated)",
                                max_length=5000,
                                verbose_name="Choices",
                            ),
                        ),
                        (
                            "enabled",
                            models.BooleanField(
                                default=True,
                                help_text="Is this parameter template enabled?",
                                verbose_name="Enabled",
                            ),
                        ),
                        (
                            "model_type",
                            models.ForeignKey(
                                blank=True,
                                help_text="Target model type for this parameter template",
                                null=True,
                                on_delete=django.db.models.deletion.SET_NULL,
                                to="contenttypes.contenttype",
                                verbose_name="Model type",
                            ),
                        ),
                        (
                            "selectionlist",
                            models.ForeignKey(
                                blank=True,
                                help_text="Selection list for this parameter",
                                null=True,
                                on_delete=django.db.models.deletion.SET_NULL,
                                related_name="templates",
                                to="common.selectionlist",
                                verbose_name="Selection List",
                            ),
                        ),
                    ],
                    options={
                        "verbose_name": "Parameter Template",
                        "verbose_name_plural": "Parameter Templates",
                        "db_table": "part_partparametertemplate",
                    },
                    bases=(
                        InvenTree.models.ContentTypeMixin,
                        InvenTree.models.PluginValidationMixin,
                        models.Model,
                    ),
                ),
            ],
            database_operations=[],
        ),
        migrations.SeparateDatabaseAndState(
            state_operations=[
                migrations.CreateModel(
                    name="Parameter",
                    fields=[
                        (
                            "id",
                            models.AutoField(
                                auto_created=True,
                                primary_key=True,
                                serialize=False,
                                verbose_name="ID",
                            ),
                        ),
                        (
                            "metadata",
                            models.JSONField(
                                blank=True,
                                help_text="JSON metadata field, for use by external plugins",
                                null=True,
                                verbose_name="Plugin Metadata",
                            ),
                        ),
                        (
                            "updated",
                            models.DateTimeField(
                                blank=True,
                                default=None,
                                help_text="Timestamp of last update",
                                null=True,
                                verbose_name="Updated",
                            ),
                        ),
                        (
                            "model_id",
                            models.PositiveIntegerField(
                                help_text="ID of the target model for this parameter",
                                verbose_name="Model ID",
                            ),
                        ),
                        (
                            "data",
                            models.CharField(
                                help_text="Parameter Value",
                                max_length=500,
                                validators=[django.core.validators.MinLengthValidator(1)],
                                verbose_name="Data",
                            ),
                        ),
                        (
                            "data_numeric",
                            models.FloatField(blank=True, default=None, null=True),
                        ),
                        (
                            "note",
                            models.CharField(
                                blank=True,
                                help_text="Optional note field",
                                max_length=500,
                                verbose_name="Note",
                            ),
                        ),
                        (
                            "model_type",
                            models.ForeignKey(
                                on_delete=django.db.models.deletion.CASCADE,
                                to="contenttypes.contenttype",
                            ),
                        ),
                        (
                            "updated_by",
                            models.ForeignKey(
                                blank=True,
                                help_text="User who last updated this object",
                                null=True,
                                on_delete=django.db.models.deletion.SET_NULL,
                                related_name="%(class)s_updated",
                                to=settings.AUTH_USER_MODEL,
                                verbose_name="Update By",
                            ),
                        ),
                        (
                            "template",
                            models.ForeignKey(
                                help_text="Parameter template",
                                on_delete=django.db.models.deletion.CASCADE,
                                related_name="parameters",
                                to="common.parametertemplate",
                                verbose_name="Template",
                            ),
                        ),
                    ],
                    options={
                        "verbose_name": "Parameter",
                        "verbose_name_plural": "Parameters",
                        "db_table": "part_partparameter",
                        "indexes": [
                            models.Index(
                                fields=["model_type", "model_id"],
                                name="part_partpa_model_t_198c9d_idx",
                            )
                        ],
                        "unique_together": {("model_type", "model_id", "template")},
                    },
                    bases=(
                        InvenTree.models.ContentTypeMixin,
                        InvenTree.models.PluginValidationMixin,
                        models.Model,
                    ),
                ),
            ],
            database_operations=[],
        ),
    ]
