# Generated by Django 5.2.8 on 2025-11-11 22:40

from decimal import Decimal

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0096_move_email_profiles"),
    ]

    operations = [
        migrations.RenameModel(
            old_name="EnergyAccount",
            new_name="CustomerAccount",
        ),
        migrations.AlterModelOptions(
            name="customeraccount",
            options={
                "verbose_name": "Customer Account",
                "verbose_name_plural": "Customer Accounts",
            },
        ),
        migrations.AlterField(
            model_name="customeraccount",
            name="user",
            field=models.OneToOneField(
                blank=True,
                null=True,
                on_delete=models.CASCADE,
                related_name="customer_account",
                to="core.user",
            ),
        ),
        migrations.AddField(
            model_name="customeraccount",
            name="balance_mxn",
            field=models.DecimalField(
                decimal_places=2,
                default=Decimal("0"),
                help_text="Available currency balance for auto top-ups.",
                max_digits=12,
            ),
        ),
        migrations.AddField(
            model_name="customeraccount",
            name="minimum_purchase_mxn",
            field=models.DecimalField(
                decimal_places=2,
                default=Decimal("0"),
                help_text="Default amount to purchase when topping up via credit card.",
                max_digits=12,
            ),
        ),
        migrations.AddField(
            model_name="customeraccount",
            name="energy_tariff",
            field=models.ForeignKey(
                blank=True,
                help_text="Tariff used to convert currency balance to energy credits.",
                null=True,
                on_delete=models.deletion.SET_NULL,
                related_name="accounts",
                to="core.energytariff",
            ),
        ),
        migrations.AddField(
            model_name="customeraccount",
            name="credit_card_brand",
            field=models.CharField(
                blank=True,
                default="",
                help_text="Brand of the backup credit card.",
                max_length=20,
            ),
        ),
        migrations.AddField(
            model_name="customeraccount",
            name="credit_card_last4",
            field=models.CharField(
                blank=True,
                default="",
                help_text="Last four digits of the backup credit card.",
                max_length=4,
            ),
        ),
        migrations.AddField(
            model_name="customeraccount",
            name="credit_card_exp_month",
            field=models.PositiveSmallIntegerField(
                blank=True,
                help_text="Expiration month for the backup credit card.",
                null=True,
                validators=[
                    django.core.validators.MinValueValidator(1),
                    django.core.validators.MaxValueValidator(12),
                ],
            ),
        ),
        migrations.AddField(
            model_name="customeraccount",
            name="credit_card_exp_year",
            field=models.PositiveSmallIntegerField(
                blank=True,
                help_text="Expiration year for the backup credit card.",
                null=True,
            ),
        ),
        migrations.CreateModel(
            name="EnergyTransaction",
            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)),
                (
                    "account",
                    models.ForeignKey(
                        on_delete=models.deletion.CASCADE,
                        related_name="energy_transactions",
                        to="core.customeraccount",
                    ),
                ),
                (
                    "tariff",
                    models.ForeignKey(
                        blank=True,
                        help_text="Tariff in effect when the purchase occurred.",
                        null=True,
                        on_delete=models.deletion.SET_NULL,
                        related_name="energy_transactions",
                        to="core.energytariff",
                    ),
                ),
                (
                    "purchased_kw",
                    models.DecimalField(
                        decimal_places=2,
                        help_text="Number of kW purchased for the account.",
                        max_digits=10,
                    ),
                ),
                (
                    "charged_amount_mxn",
                    models.DecimalField(
                        decimal_places=2,
                        help_text="Currency amount used for the purchase.",
                        max_digits=12,
                    ),
                ),
                (
                    "conversion_factor",
                    models.DecimalField(
                        decimal_places=6,
                        help_text="Conversion factor (kW per MXN) applied at purchase time.",
                        max_digits=12,
                    ),
                ),
                (
                    "created_on",
                    models.DateTimeField(auto_now_add=True),
                ),
            ],
            options={
                "ordering": ("-created_on",),
                "verbose_name": "Energy Transaction",
                "verbose_name_plural": "Energy Transactions",
            },
        ),
        migrations.AlterField(
            model_name="user",
            name="is_active",
            field=models.BooleanField(
                default=True,
                help_text=(
                    "Designates whether this user should be treated as active. Unselect this instead of deleting customer accounts."
                ),
                verbose_name="active",
            ),
        ),
    ]
