from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ("sensor_data", "0011_sensordata_irrigation_method"),
    ]

    operations = [
        migrations.CreateModel(
            name="PlantCatalogSnapshot",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("backend_plant_id", models.PositiveIntegerField(db_index=True, help_text="شناسه گیاه در Backend/plants", unique=True)),
                ("name", models.CharField(db_index=True, max_length=255)),
                ("slug", models.SlugField(blank=True, default="", max_length=255)),
                ("icon", models.CharField(blank=True, default="leaf", max_length=255)),
                ("description", models.TextField(blank=True, default="")),
                ("metadata", models.JSONField(blank=True, default=dict)),
                ("light", models.CharField(blank=True, default="", max_length=255)),
                ("watering", models.CharField(blank=True, default="", max_length=255)),
                ("soil", models.CharField(blank=True, default="", max_length=255)),
                ("temperature", models.CharField(blank=True, default="", max_length=255)),
                ("growth_stage", models.CharField(blank=True, default="", max_length=255)),
                ("growth_stages", models.JSONField(blank=True, default=list)),
                ("planting_season", models.CharField(blank=True, default="", max_length=255)),
                ("harvest_time", models.CharField(blank=True, default="", max_length=255)),
                ("spacing", models.CharField(blank=True, default="", max_length=255)),
                ("fertilizer", models.CharField(blank=True, default="", max_length=255)),
                ("health_profile", models.JSONField(blank=True, default=dict)),
                ("irrigation_profile", models.JSONField(blank=True, default=dict)),
                ("growth_profile", models.JSONField(blank=True, default=dict)),
                ("is_active", models.BooleanField(default=True)),
                ("source_updated_at", models.DateTimeField(blank=True, help_text="updated_at رکورد canonical در Backend", null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "plant catalog snapshot",
                "verbose_name_plural": "plant catalog snapshots",
                "db_table": "farm_data_plantcatalogsnapshot",
                "ordering": ["name", "backend_plant_id"],
            },
        ),
        migrations.CreateModel(
            name="FarmPlantAssignment",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("position", models.PositiveIntegerField(default=0)),
                ("stage", models.CharField(blank=True, default="", max_length=64)),
                ("metadata", models.JSONField(blank=True, default=dict)),
                ("assigned_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("farm", models.ForeignKey(db_column="farm_uuid", on_delete=django.db.models.deletion.CASCADE, related_name="plant_assignments", to="sensor_data.sensordata")),
                ("plant", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name="farm_assignments", to="sensor_data.plantcatalogsnapshot")),
            ],
            options={
                "verbose_name": "farm plant assignment",
                "verbose_name_plural": "farm plant assignments",
                "db_table": "farm_data_farmplantassignment",
                "ordering": ["position", "id"],
            },
        ),
        migrations.AddConstraint(
            model_name="farmplantassignment",
            constraint=models.UniqueConstraint(fields=("farm", "plant"), name="farm_data_unique_farm_plant_assignment"),
        ),
    ]
