# Generated by Django 5.2.8 on 2025-12-06 15:03

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


class Migration(migrations.Migration):

    initial = False

    dependencies = [
        ("cards", "0002_initial"),
        ("energy", "0001_initial"),
        ("groups", "0002_initial"),
        ("links", "0002_initial"),
        ("maps", "0002_initial"),
        ("nodes", "0002_initial"),
        ("ocpp", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AddField(
            model_name="charger",
            name="owner_users",
            field=models.ManyToManyField(
                blank=True,
                help_text="Users who can view this charge point.",
                related_name="owned_chargers",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="charger",
            name="reference",
            field=models.OneToOneField(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to="links.reference",
            ),
        ),
        migrations.AddField(
            model_name="charger",
            name="ws_auth_group",
            field=models.ForeignKey(
                blank=True,
                help_text="Charge point connections must authenticate with HTTP Basic as a member of this security group.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="ws_group_authenticated_chargers",
                to="groups.securitygroup",
                verbose_name="WS Auth Group",
            ),
        ),
        migrations.AddField(
            model_name="charger",
            name="ws_auth_user",
            field=models.ForeignKey(
                blank=True,
                help_text="Charge point connections must authenticate with HTTP Basic using this user.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="ws_authenticated_chargers",
                to=settings.AUTH_USER_MODEL,
                verbose_name="WS Auth User",
            ),
        ),
        migrations.CreateModel(
            name="EVCSChargePoint",
            fields=[],
            options={
                "verbose_name": "EVCS Charge Point",
                "verbose_name_plural": "EVCS Charge Points",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("ocpp.charger",),
        ),
        migrations.AddField(
            model_name="charger",
            name="configuration",
            field=models.ForeignKey(
                blank=True,
                help_text="Latest GetConfiguration response received from this charge point.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="chargers",
                to="ocpp.chargerconfiguration",
            ),
        ),
        migrations.AddField(
            model_name="chargerlogrequest",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="log_requests",
                to="ocpp.charger",
            ),
        ),
        migrations.AddField(
            model_name="chargingprofile",
            name="charger",
            field=models.ForeignKey(
                blank=True,
                help_text="Optional default charger context for the profile.",
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="charging_profiles",
                to="ocpp.charger",
                verbose_name="Charger",
            ),
        ),
        migrations.AddField(
            model_name="chargingprofiledispatch",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="charging_profile_dispatches",
                to="ocpp.charger",
            ),
        ),
        migrations.AddField(
            model_name="chargingprofiledispatch",
            name="profile",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="dispatches",
                to="ocpp.chargingprofile",
            ),
        ),
        migrations.AddField(
            model_name="chargingschedule",
            name="profile",
            field=models.OneToOneField(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="schedule",
                to="ocpp.chargingprofile",
            ),
        ),
        migrations.AddField(
            model_name="configurationkey",
            name="configuration",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="configuration_entries",
                to="ocpp.chargerconfiguration",
            ),
        ),
        migrations.AddField(
            model_name="cpfirmware",
            name="source_charger",
            field=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",
            ),
        ),
        migrations.AddField(
            model_name="cpfirmware",
            name="source_node",
            field=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",
            ),
        ),
        migrations.AddField(
            model_name="cpfirmwaredeployment",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="firmware_deployments",
                to="ocpp.charger",
                verbose_name="Charge point",
            ),
        ),
        migrations.AddField(
            model_name="cpfirmwaredeployment",
            name="firmware",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="deployments",
                to="ocpp.cpfirmware",
                verbose_name="Firmware",
            ),
        ),
        migrations.AddField(
            model_name="cpfirmwaredeployment",
            name="node",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="firmware_deployments",
                to="nodes.node",
                verbose_name="Node",
            ),
        ),
        migrations.AddField(
            model_name="cpfirmwarerequest",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="firmware_requests",
                to="ocpp.charger",
            ),
        ),
        migrations.AddField(
            model_name="cpforwarder",
            name="source_node",
            field=models.ForeignKey(
                blank=True,
                help_text="Node providing the original charge point connection.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="outgoing_forwarders",
                to="nodes.node",
            ),
        ),
        migrations.AddField(
            model_name="cpforwarder",
            name="target_node",
            field=models.ForeignKey(
                help_text="Remote node that will receive forwarded sessions.",
                on_delete=django.db.models.deletion.CASCADE,
                related_name="incoming_forwarders",
                to="nodes.node",
            ),
        ),
        migrations.AddField(
            model_name="charger",
            name="network_profile",
            field=models.ForeignKey(
                blank=True,
                help_text="Last network profile that was successfully applied to this charge point.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="chargers",
                to="ocpp.cpnetworkprofile",
            ),
        ),
        migrations.AddField(
            model_name="cpnetworkprofiledeployment",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="network_profile_deployments",
                to="ocpp.charger",
                verbose_name="Charge point",
            ),
        ),
        migrations.AddField(
            model_name="cpnetworkprofiledeployment",
            name="network_profile",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="deployments",
                to="ocpp.cpnetworkprofile",
                verbose_name="Network profile",
            ),
        ),
        migrations.AddField(
            model_name="cpnetworkprofiledeployment",
            name="node",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="network_profile_deployments",
                to="nodes.node",
                verbose_name="Node",
            ),
        ),
        migrations.AddField(
            model_name="cpreservation",
            name="account",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="cp_reservations",
                to="energy.customeraccount",
                verbose_name="Energy account",
            ),
        ),
        migrations.AddField(
            model_name="cpreservation",
            name="connector",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="reservations",
                to="ocpp.charger",
                verbose_name="Connector",
            ),
        ),
        migrations.AddField(
            model_name="cpreservation",
            name="location",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.PROTECT,
                related_name="reservations",
                to="maps.location",
                verbose_name="Location",
            ),
        ),
        migrations.AddField(
            model_name="cpreservation",
            name="rfid",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="cp_reservations",
                to="cards.rfid",
                verbose_name="RFID",
            ),
        ),
        migrations.AddField(
            model_name="datatransfermessage",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="data_transfer_messages",
                to="ocpp.charger",
            ),
        ),
        migrations.AddField(
            model_name="cpfirmwarerequest",
            name="message",
            field=models.OneToOneField(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="firmware_request",
                to="ocpp.datatransfermessage",
            ),
        ),
        migrations.AddField(
            model_name="metervalue",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="meter_values",
                to="ocpp.charger",
            ),
        ),
        migrations.CreateModel(
            name="MeterReading",
            fields=[],
            options={
                "verbose_name": "Meter Value",
                "verbose_name_plural": "Meter Values",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("ocpp.metervalue",),
        ),
        migrations.AddField(
            model_name="powerprojection",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="power_projections",
                to="ocpp.charger",
                verbose_name="Charger",
            ),
        ),
        migrations.AddField(
            model_name="rfidsessionattempt",
            name="account",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="rfid_attempts",
                to="energy.customeraccount",
            ),
        ),
        migrations.AddField(
            model_name="rfidsessionattempt",
            name="charger",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="rfid_attempts",
                to="ocpp.charger",
            ),
        ),
        migrations.AddField(
            model_name="securityevent",
            name="charger",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="security_events",
                to="ocpp.charger",
            ),
        ),
        migrations.AddField(
            model_name="simulator",
            name="configuration",
            field=models.ForeignKey(
                blank=True,
                help_text="CP Configuration returned for GetConfiguration calls.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="simulators",
                to="ocpp.chargerconfiguration",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="stationmodel",
            unique_together={("vendor", "model_family", "model")},
        ),
        migrations.AddField(
            model_name="charger",
            name="station_model",
            field=models.ForeignKey(
                blank=True,
                help_text="Optional hardware model for this EVCS.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="chargers",
                to="ocpp.stationmodel",
                verbose_name="Station Model",
            ),
        ),
        migrations.AddField(
            model_name="transaction",
            name="account",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="transactions",
                to="energy.customeraccount",
            ),
        ),
        migrations.AddField(
            model_name="transaction",
            name="charger",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="transactions",
                to="ocpp.charger",
            ),
        ),
        migrations.AddField(
            model_name="rfidsessionattempt",
            name="transaction",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="rfid_attempts",
                to="ocpp.transaction",
            ),
        ),
        migrations.AddField(
            model_name="metervalue",
            name="transaction",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="meter_values",
                to="ocpp.transaction",
            ),
        ),
        migrations.AddConstraint(
            model_name="chargingprofile",
            constraint=models.UniqueConstraint(
                condition=models.Q(("charger__isnull", False)),
                fields=("charger", "connector_id", "charging_profile_id"),
                name="unique_charging_profile_per_connector",
            ),
        ),
        migrations.AddConstraint(
            model_name="chargingprofiledispatch",
            constraint=models.UniqueConstraint(
                fields=("profile", "charger", "message_id"),
                name="unique_charging_profile_dispatch_message",
            ),
        ),
        migrations.AddIndex(
            model_name="cpfirmwaredeployment",
            index=models.Index(
                fields=["ocpp_message_id"], name="ocpp_cpfirm_ocpp_me_881925_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="cpfirmwaredeployment",
            index=models.Index(
                fields=["download_token"], name="ocpp_cpfirm_downloa_7f183a_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="cpforwarder",
            constraint=models.UniqueConstraint(
                fields=("source_node", "target_node"),
                name="unique_forwarder_per_target",
            ),
        ),
        migrations.AddIndex(
            model_name="cpnetworkprofiledeployment",
            index=models.Index(
                fields=["ocpp_message_id"], name="ocpp_cpnetw_ocpp_me_cc48cb_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="datatransfermessage",
            index=models.Index(
                fields=["ocpp_message_id"], name="ocpp_datatr_ocpp_me_70d17f_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="datatransfermessage",
            index=models.Index(
                fields=["vendor_id"], name="ocpp_datatr_vendor__59e1c7_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="simulator",
            constraint=models.UniqueConstraint(
                condition=models.Q(("default", True), ("is_deleted", False)),
                fields=("default",),
                name="unique_default_simulator",
            ),
        ),
        migrations.AddConstraint(
            model_name="charger",
            constraint=models.UniqueConstraint(
                condition=models.Q(("connector_id__isnull", False)),
                fields=("charger_id", "connector_id"),
                name="charger_connector_unique",
            ),
        ),
        migrations.AddConstraint(
            model_name="charger",
            constraint=models.UniqueConstraint(
                condition=models.Q(("connector_id__isnull", True)),
                fields=("charger_id",),
                name="charger_unique_without_connector",
            ),
        ),
        migrations.AddConstraint(
            model_name="charger",
            constraint=models.CheckConstraint(
                condition=models.Q(
                    ("ws_auth_user__isnull", True),
                    ("ws_auth_group__isnull", True),
                    _connector="OR",
                ),
                name="charger_ws_auth_user_or_group",
            ),
        ),
    ]
