# Generated by Django 4.2.17 on 2025-03-05 14:03

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


class Migration(migrations.Migration):
    dependencies = [("counter", "0029_alter_selling_label")]

    operations = [
        migrations.CreateModel(
            name="ReturnableProduct",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "max_return",
                    models.PositiveSmallIntegerField(
                        default=0,
                        help_text=(
                            "The maximum number of items a customer can return "
                            "without having actually bought them."
                        ),
                        verbose_name="maximum returns",
                    ),
                ),
                (
                    "product",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="cons",
                        to="counter.product",
                        verbose_name="returnable product",
                    ),
                ),
                (
                    "returned_product",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="dcons",
                        to="counter.product",
                        verbose_name="returned product",
                    ),
                ),
            ],
            options={
                "verbose_name": "returnable product",
                "verbose_name_plural": "returnable products",
            },
        ),
        migrations.AddConstraint(
            model_name="returnableproduct",
            constraint=models.CheckConstraint(
                condition=models.Q(
                    ("product", models.F("returned_product")), _negated=True
                ),
                name="returnableproduct_product_different_from_returned",
                violation_error_message="The returnable product cannot be the same as the returned one",
            ),
        ),
        migrations.CreateModel(
            name="ReturnableProductBalance",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("balance", models.SmallIntegerField(blank=True, default=0)),
                (
                    "customer",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="return_balances",
                        to="counter.customer",
                    ),
                ),
                (
                    "returnable",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="balances",
                        to="counter.returnableproduct",
                    ),
                ),
            ],
        ),
        migrations.AddConstraint(
            model_name="returnableproductbalance",
            constraint=models.UniqueConstraint(
                fields=("customer", "returnable"),
                name="returnable_product_unique_type_per_customer",
            ),
        ),
        migrations.RemoveField(model_name="customer", name="recorded_products"),
    ]
