# Generated by Django 5.2.8 on 2025-11-16 15:07

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


class Migration(migrations.Migration):

    dependencies = [
        ("ocpp", "0052_evcschargepoint"),
    ]

    operations = [
        migrations.CreateModel(
            name="ChargingProfile",
            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)),
                (
                    "connector_id",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Connector targeted by this profile (0 sends the profile to the EVCS).",
                        verbose_name="Connector ID",
                    ),
                ),
                (
                    "charging_profile_id",
                    models.PositiveIntegerField(
                        help_text="Identifier sent as chargingProfileId in OCPP payloads.",
                        verbose_name="Charging Profile ID",
                    ),
                ),
                (
                    "stack_level",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Priority applied when multiple profiles overlap.",
                        verbose_name="Stack Level",
                    ),
                ),
                (
                    "purpose",
                    models.CharField(
                        choices=[
                            ("ChargePointMaxProfile", "Charge Point Max Profile"),
                            ("TxDefaultProfile", "Transaction Default Profile"),
                            ("TxProfile", "Transaction Profile"),
                        ],
                        max_length=32,
                        verbose_name="Purpose",
                    ),
                ),
                (
                    "kind",
                    models.CharField(
                        choices=[
                            ("Absolute", "Absolute"),
                            ("Recurring", "Recurring"),
                            ("Relative", "Relative"),
                        ],
                        max_length=16,
                        verbose_name="Profile Kind",
                    ),
                ),
                (
                    "recurrency_kind",
                    models.CharField(
                        blank=True,
                        choices=[("Daily", "Daily"), ("Weekly", "Weekly")],
                        default="",
                        max_length=16,
                        verbose_name="Recurrency Kind",
                    ),
                ),
                (
                    "transaction_id",
                    models.PositiveIntegerField(
                        blank=True,
                        help_text="Required when Purpose is TxProfile.",
                        null=True,
                        verbose_name="Transaction ID",
                    ),
                ),
                ("valid_from", models.DateTimeField(blank=True, null=True)),
                ("valid_to", models.DateTimeField(blank=True, null=True)),
                (
                    "start_schedule",
                    models.DateTimeField(
                        blank=True,
                        help_text="Optional schedule start time; defaults to immediate execution.",
                        null=True,
                    ),
                ),
                (
                    "duration_seconds",
                    models.PositiveIntegerField(
                        blank=True, null=True, verbose_name="Duration (seconds)"
                    ),
                ),
                (
                    "charging_rate_unit",
                    models.CharField(
                        choices=[("A", "Amperes"), ("W", "Watts")],
                        max_length=2,
                        verbose_name="Charging Rate Unit",
                    ),
                ),
                (
                    "charging_schedule_periods",
                    models.JSONField(
                        blank=True,
                        default=list,
                        help_text="List of schedule periods including start_period, limit, number_phases, and phase_to_use values.",
                    ),
                ),
                (
                    "min_charging_rate",
                    models.DecimalField(
                        blank=True,
                        decimal_places=3,
                        max_digits=10,
                        null=True,
                        verbose_name="Minimum Charging Rate",
                    ),
                ),
                (
                    "description",
                    models.CharField(blank=True, default="", max_length=255),
                ),
                (
                    "last_status",
                    models.CharField(blank=True, default="", max_length=32),
                ),
                (
                    "last_status_info",
                    models.CharField(blank=True, default="", max_length=255),
                ),
                ("last_response_payload", models.JSONField(blank=True, default=dict)),
                ("last_response_at", models.DateTimeField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "charger",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="charging_profiles",
                        to="ocpp.charger",
                        verbose_name="Charger",
                    ),
                ),
            ],
            options={
                "verbose_name": "Charging Profile",
                "verbose_name_plural": "Charging Profiles",
                "ordering": [
                    "charger__charger_id",
                    "connector_id",
                    "-stack_level",
                    "charging_profile_id",
                ],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("charger", "connector_id", "charging_profile_id"),
                        name="unique_charging_profile_per_connector",
                    )
                ],
            },
        ),
    ]
