# Generated by Django 5.2.1 on 2026-09-01 09:52

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("shop_management", "0080_company_setting_and_warehouse"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AddField(
            model_name="product",
            name="barcode",
            field=models.CharField(
                blank=True, db_index=True, max_length=100, null=True
            ),
        ),
        migrations.AddField(
            model_name="product",
            name="default_unit",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="default_for_products",
                to="shop_management.unit",
            ),
        ),
        migrations.AddField(
            model_name="product",
            name="is_active",
            field=models.BooleanField(default=True),
        ),
        migrations.AddField(
            model_name="product",
            name="minimum_stock_level",
            field=models.DecimalField(decimal_places=4, default=0, max_digits=18),
        ),
        migrations.AddField(
            model_name="product",
            name="requires_batch",
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name="product",
            name="requires_expiry",
            field=models.BooleanField(default=False),
        ),
        migrations.CreateModel(
            name="ProductPrice",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, null=True)),
                ("updated_at", models.DateTimeField(auto_now=True, null=True)),
                (
                    "price_type",
                    models.CharField(
                        choices=[("RETAIL", "Retail"), ("WHOLESALE", "Wholesale")],
                        max_length=20,
                    ),
                ),
                ("amount", models.DecimalField(decimal_places=4, max_digits=18)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="%(class)s_created",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "currency",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="product_prices",
                        to="shop_management.currency",
                    ),
                ),
                (
                    "product",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="prices",
                        to="shop_management.product",
                    ),
                ),
            ],
            options={
                "ordering": ["product_id", "currency_id", "price_type"],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("product", "currency", "price_type"),
                        name="uniq_product_currency_price_type",
                    ),
                    models.CheckConstraint(
                        check=models.Q(("amount__gte", 0)),
                        name="product_price_nonnegative",
                    ),
                ],
            },
        ),
    ]
