# Generated by Django 4.2.7 on 2025-12-19 08:22

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


class Migration(migrations.Migration):
    dependencies = [
        ("subscriptions", "0002_subscription_discount_amount_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="BulkDiscount",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "min_students",
                    models.IntegerField(
                        help_text="От какого количества учеников действует эта цена",
                        validators=[django.core.validators.MinValueValidator(1)],
                        verbose_name="Минимальное количество учеников",
                    ),
                ),
                (
                    "max_students",
                    models.IntegerField(
                        blank=True,
                        help_text="До какого количества учеников действует эта цена. Если не указано - без ограничений",
                        null=True,
                        validators=[django.core.validators.MinValueValidator(1)],
                        verbose_name="Максимальное количество учеников",
                    ),
                ),
                (
                    "total_price",
                    models.DecimalField(
                        decimal_places=2,
                        help_text="Общая цена за указанное количество учеников",
                        max_digits=10,
                        validators=[django.core.validators.MinValueValidator(0)],
                        verbose_name="Итоговая цена",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Дата обновления"),
                ),
                (
                    "plan",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="bulk_discounts",
                        to="subscriptions.subscriptionplan",
                        verbose_name="Тарифный план",
                    ),
                ),
            ],
            options={
                "verbose_name": "Прогрессирующая скидка",
                "verbose_name_plural": "Прогрессирующие скидки",
                "db_table": "bulk_discounts",
                "ordering": ["plan", "min_students"],
                "indexes": [
                    models.Index(
                        fields=["plan", "min_students"],
                        name="bulk_discou_plan_id_7121b9_idx",
                    )
                ],
            },
        ),
        migrations.AddConstraint(
            model_name="bulkdiscount",
            constraint=models.CheckConstraint(
                check=models.Q(
                    ("max_students__isnull", True),
                    ("max_students__gte", models.F("min_students")),
                    _connector="OR",
                ),
                name="max_students_gte_min_students",
            ),
        ),
    ]
