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

import apps.locale.language
import django.core.validators
from decimal import Decimal
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="ClientReport",
            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)),
                ("start_date", models.DateField()),
                ("end_date", models.DateField()),
                ("created_on", models.DateTimeField(auto_now_add=True)),
                ("data", models.JSONField(default=dict)),
                (
                    "language",
                    models.CharField(
                        choices=[
                            ("es", "Spanish (Latin America)"),
                            ("en", "English"),
                            ("it", "Italian"),
                            ("de", "German"),
                        ],
                        default=apps.locale.language.default_report_language,
                        max_length=12,
                    ),
                ),
                (
                    "title",
                    models.CharField(
                        blank=True, default="", max_length=200, verbose_name="Title"
                    ),
                ),
                ("recipients", models.JSONField(blank=True, default=list)),
                ("disable_emails", models.BooleanField(default=False)),
            ],
            options={
                "verbose_name": "Consumer Report",
                "verbose_name_plural": "Consumer Reports",
                "db_table": "core_client_report",
                "ordering": ["-created_on"],
            },
        ),
        migrations.CreateModel(
            name="ClientReportSchedule",
            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)),
                (
                    "periodicity",
                    models.CharField(
                        choices=[
                            ("none", "One-time"),
                            ("daily", "Daily"),
                            ("weekly", "Weekly"),
                            ("monthly", "Monthly"),
                            ("bimonthly", "Bi-monthly (2 months)"),
                            ("quarterly", "Quarterly"),
                            ("yearly", "Yearly"),
                        ],
                        default="none",
                        max_length=12,
                    ),
                ),
                (
                    "language",
                    models.CharField(
                        choices=[
                            ("es", "Spanish (Latin America)"),
                            ("en", "English"),
                            ("it", "Italian"),
                            ("de", "German"),
                        ],
                        default=apps.locale.language.default_report_language,
                        max_length=12,
                    ),
                ),
                (
                    "title",
                    models.CharField(
                        blank=True, default="", max_length=200, verbose_name="Title"
                    ),
                ),
                ("email_recipients", models.JSONField(blank=True, default=list)),
                ("disable_emails", models.BooleanField(default=False)),
                ("last_generated_on", models.DateTimeField(blank=True, null=True)),
            ],
            options={
                "verbose_name": "Client Report Schedule",
                "verbose_name_plural": "Client Report Schedules",
                "db_table": "core_clientreportschedule",
            },
        ),
        migrations.CreateModel(
            name="CustomerAccount",
            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(max_length=100, unique=True)),
                (
                    "odoo_customer",
                    models.JSONField(
                        blank=True,
                        help_text="Selected customer from Odoo (id, name, and contact details)",
                        null=True,
                    ),
                ),
                (
                    "service_account",
                    models.BooleanField(
                        default=False,
                        help_text="Allow transactions even when the balance is zero or negative",
                    ),
                ),
                (
                    "balance_mxn",
                    models.DecimalField(
                        decimal_places=2,
                        default=Decimal("0"),
                        help_text="Available currency balance for auto top-ups.",
                        max_digits=12,
                    ),
                ),
                (
                    "minimum_purchase_mxn",
                    models.DecimalField(
                        decimal_places=2,
                        default=Decimal("0"),
                        help_text="Default amount to purchase when topping up via credit card.",
                        max_digits=12,
                    ),
                ),
                (
                    "credit_card_brand",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Brand of the backup credit card.",
                        max_length=20,
                    ),
                ),
                (
                    "credit_card_last4",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Last four digits of the backup credit card.",
                        max_length=4,
                    ),
                ),
                (
                    "credit_card_exp_month",
                    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),
                        ],
                    ),
                ),
                (
                    "credit_card_exp_year",
                    models.PositiveSmallIntegerField(
                        blank=True,
                        help_text="Expiration year for the backup credit card.",
                        null=True,
                    ),
                ),
                (
                    "live_subscription_start_date",
                    models.DateField(blank=True, null=True),
                ),
                (
                    "live_subscription_next_renewal",
                    models.DateField(blank=True, null=True),
                ),
            ],
            options={
                "verbose_name": "Customer Account",
                "verbose_name_plural": "Customer Accounts",
                "db_table": "core_account",
            },
        ),
        migrations.CreateModel(
            name="EnergyTariff",
            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)),
                (
                    "year",
                    models.PositiveIntegerField(
                        help_text="Calendar year when the tariff applies.",
                        validators=[django.core.validators.MinValueValidator(2000)],
                    ),
                ),
                (
                    "season",
                    models.CharField(
                        choices=[
                            ("annual", "All year"),
                            ("summer", "Summer season"),
                            ("non_summer", "Non-summer season"),
                        ],
                        default="annual",
                        help_text="Season or applicability window defined by CFE.",
                        max_length=16,
                    ),
                ),
                (
                    "zone",
                    models.CharField(
                        choices=[
                            ("1", "Zone 1"),
                            ("1A", "Zone 1A"),
                            ("1B", "Zone 1B"),
                            ("1C", "Zone 1C"),
                            ("1D", "Zone 1D"),
                            ("1E", "Zone 1E"),
                            ("1F", "Zone 1F"),
                        ],
                        help_text="CFE climate zone associated with the tariff.",
                        max_length=3,
                    ),
                ),
                (
                    "contract_type",
                    models.CharField(
                        choices=[
                            ("domestic", "Domestic service (Tarifa 1)"),
                            ("dac", "High consumption domestic (DAC)"),
                            ("pdbt", "General service low demand (PDBT)"),
                            ("gdbt", "General service high demand (GDBT)"),
                            ("gdmto", "General distribution medium tension (GDMTO)"),
                            (
                                "gdmth",
                                "General distribution medium tension hourly (GDMTH)",
                            ),
                        ],
                        help_text="Type of service contract regulated by CFE.",
                        max_length=16,
                    ),
                ),
                (
                    "period",
                    models.CharField(
                        choices=[
                            ("flat", "Flat rate"),
                            ("basic", "Basic block"),
                            ("intermediate_1", "Intermediate block 1"),
                            ("intermediate_2", "Intermediate block 2"),
                            ("excess", "Excess consumption"),
                            ("base", "Base"),
                            ("intermediate", "Intermediate"),
                            ("peak", "Peak"),
                            ("critical_peak", "Critical peak"),
                            ("demand", "Demand charge"),
                            ("capacity", "Capacity charge"),
                            ("distribution", "Distribution charge"),
                            ("fixed", "Fixed charge"),
                        ],
                        help_text="Tariff block, demand component, or time-of-use period.",
                        max_length=32,
                    ),
                ),
                (
                    "unit",
                    models.CharField(
                        choices=[
                            ("kwh", "Kilowatt-hour"),
                            ("kw", "Kilowatt"),
                            ("month", "Monthly charge"),
                        ],
                        default="kwh",
                        help_text="Measurement unit for the tariff charge.",
                        max_length=16,
                    ),
                ),
                (
                    "start_time",
                    models.TimeField(
                        help_text="Start time for the tariff's applicability window."
                    ),
                ),
                (
                    "end_time",
                    models.TimeField(
                        help_text="End time for the tariff's applicability window."
                    ),
                ),
                (
                    "price_mxn",
                    models.DecimalField(
                        decimal_places=4,
                        help_text="Customer price per unit in MXN.",
                        max_digits=10,
                    ),
                ),
                (
                    "cost_mxn",
                    models.DecimalField(
                        decimal_places=4,
                        help_text="Provider cost per unit in MXN.",
                        max_digits=10,
                    ),
                ),
                (
                    "notes",
                    models.TextField(
                        blank=True,
                        default="",
                        help_text="Context or special billing conditions published by CFE.",
                    ),
                ),
            ],
            options={
                "verbose_name": "Energy Tariff",
                "verbose_name_plural": "Energy Tariffs",
                "db_table": "core_energytariff",
                "ordering": (
                    "-year",
                    "season",
                    "zone",
                    "contract_type",
                    "period",
                    "start_time",
                ),
            },
        ),
        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)),
                (
                    "direction",
                    models.CharField(
                        choices=[("credit", "Credit"), ("debit", "Debit")],
                        default="credit",
                        help_text="Whether this ledger entry is a credit or debit.",
                        max_length=10,
                    ),
                ),
                (
                    "delta_kw",
                    models.DecimalField(
                        decimal_places=4,
                        help_text="Signed kW impact on the account balance (credits positive).",
                        max_digits=12,
                    ),
                ),
                (
                    "charged_amount_mxn",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Currency amount for the transaction when applicable.",
                        max_digits=12,
                        null=True,
                    ),
                ),
                (
                    "conversion_factor",
                    models.DecimalField(
                        blank=True,
                        decimal_places=6,
                        help_text="Conversion factor (kW per MXN) applied at purchase time.",
                        max_digits=12,
                        null=True,
                    ),
                ),
                (
                    "source",
                    models.CharField(
                        choices=[
                            ("card_topup", "Card top-up"),
                            ("subscription", "Subscription"),
                            ("session_close", "Session close"),
                            ("manual_adjustment", "Manual adjustment"),
                        ],
                        default="manual_adjustment",
                        help_text="Originating flow for this ledger entry.",
                        max_length=32,
                    ),
                ),
                (
                    "reference",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Optional reference identifier for reconciliation.",
                        max_length=64,
                    ),
                ),
                ("created_on", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "verbose_name": "Energy Transaction",
                "verbose_name_plural": "Energy Transactions",
                "db_table": "core_energytransaction",
                "ordering": ("-created_on",),
            },
        ),
    ]
