# Generated by Django 5.2.7 on 2025-11-05 21:34

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


class Migration(migrations.Migration):

    dependencies = [
        ("nodes", "0026_alter_node_port"),
        ("ocpp", "0036_merge_20251101_1759"),
    ]

    operations = [
        migrations.CreateModel(
            name="CPFirmware",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                (
                    "name",
                    models.CharField(blank=True, max_length=200, verbose_name="Name"),
                ),
                (
                    "description",
                    models.TextField(blank=True, verbose_name="Description"),
                ),
                (
                    "source",
                    models.CharField(
                        choices=[("download", "Downloaded"), ("upload", "Uploaded")],
                        default="download",
                        max_length=16,
                        verbose_name="Source",
                    ),
                ),
                (
                    "content_type",
                    models.CharField(
                        blank=True,
                        default="application/octet-stream",
                        max_length=100,
                        verbose_name="Content type",
                    ),
                ),
                (
                    "filename",
                    models.CharField(
                        blank=True, max_length=255, verbose_name="Filename"
                    ),
                ),
                ("payload_json", models.JSONField(blank=True, null=True)),
                ("payload_binary", models.BinaryField(blank=True, null=True)),
                (
                    "payload_encoding",
                    models.CharField(
                        blank=True, max_length=32, verbose_name="Encoding"
                    ),
                ),
                (
                    "payload_size",
                    models.PositiveIntegerField(default=0, verbose_name="Payload size"),
                ),
                (
                    "checksum",
                    models.CharField(
                        blank=True, max_length=128, verbose_name="Checksum"
                    ),
                ),
                ("metadata", models.JSONField(blank=True, default=dict)),
                (
                    "download_vendor_id",
                    models.CharField(
                        blank=True, max_length=255, verbose_name="Vendor ID"
                    ),
                ),
                (
                    "download_message_id",
                    models.CharField(
                        blank=True, max_length=64, verbose_name="Message ID"
                    ),
                ),
                (
                    "downloaded_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Downloaded at"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "source_charger",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="downloaded_firmware",
                        to="ocpp.charger",
                        verbose_name="Source charge point",
                    ),
                ),
                (
                    "source_node",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="downloaded_firmware",
                        to="nodes.node",
                        verbose_name="Source node",
                    ),
                ),
            ],
            options={
                "verbose_name": "CP Firmware",
                "verbose_name_plural": "CP Firmware",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="CPFirmwareDeployment",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                (
                    "ocpp_message_id",
                    models.CharField(
                        blank=True, max_length=64, verbose_name="OCPP message ID"
                    ),
                ),
                (
                    "status",
                    models.CharField(blank=True, max_length=32, verbose_name="Status"),
                ),
                (
                    "status_info",
                    models.CharField(
                        blank=True, max_length=255, verbose_name="Status details"
                    ),
                ),
                (
                    "status_timestamp",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Status timestamp"
                    ),
                ),
                (
                    "requested_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Requested at"
                    ),
                ),
                (
                    "completed_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Completed at"
                    ),
                ),
                (
                    "retrieve_date",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Retrieve date"
                    ),
                ),
                (
                    "retry_count",
                    models.PositiveIntegerField(default=0, verbose_name="Retries"),
                ),
                (
                    "retry_interval",
                    models.PositiveIntegerField(
                        default=0, verbose_name="Retry interval (seconds)"
                    ),
                ),
                (
                    "download_token",
                    models.CharField(
                        blank=True, max_length=64, verbose_name="Download token"
                    ),
                ),
                (
                    "download_token_expires_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Token expires at"
                    ),
                ),
                (
                    "downloaded_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Downloaded at"
                    ),
                ),
                ("request_payload", models.JSONField(blank=True, default=dict)),
                ("response_payload", models.JSONField(blank=True, default=dict)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "charger",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="firmware_deployments",
                        to="ocpp.charger",
                        verbose_name="Charge point",
                    ),
                ),
                (
                    "firmware",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="deployments",
                        to="ocpp.cpfirmware",
                        verbose_name="Firmware",
                    ),
                ),
                (
                    "node",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="firmware_deployments",
                        to="nodes.node",
                        verbose_name="Node",
                    ),
                ),
            ],
            options={
                "verbose_name": "CP Firmware deployment",
                "verbose_name_plural": "CP Firmware deployments",
                "ordering": ["-requested_at"],
                "indexes": [
                    models.Index(
                        fields=["ocpp_message_id"],
                        name="ocpp_cpfirm_ocpp_me_881925_idx",
                    ),
                    models.Index(
                        fields=["download_token"], name="ocpp_cpfirm_downloa_7f183a_idx"
                    ),
                ],
            },
        ),
    ]
