# Generated by Django 4.0.5 on 2022-10-26 21:54

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


class Migration(migrations.Migration):
    dependencies = [
        (
            "metering_billing",
            "0052_rename_payment_providers_customer_integrations_and_more",
        ),
    ]

    operations = [
        migrations.AddField(
            model_name="historicalplan",
            name="parent_plan",
            field=models.ForeignKey(
                blank=True,
                db_constraint=False,
                null=True,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="+",
                to="metering_billing.plan",
            ),
        ),
        migrations.AddField(
            model_name="historicalplan",
            name="target_customer",
            field=models.ForeignKey(
                blank=True,
                db_constraint=False,
                null=True,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="+",
                to="metering_billing.customer",
            ),
        ),
        migrations.AddField(
            model_name="plan",
            name="parent_plan",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="child_plans",
                to="metering_billing.plan",
            ),
        ),
        migrations.AddField(
            model_name="plan",
            name="target_customer",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="custom_plans",
                to="metering_billing.customer",
            ),
        ),
        migrations.AddConstraint(
            model_name="plan",
            constraint=models.CheckConstraint(
                check=models.Q(
                    models.Q(
                        ("parent_plan__isnull", True), ("target_customer__isnull", True)
                    ),
                    models.Q(
                        ("parent_plan__isnull", False),
                        ("target_customer__isnull", False),
                    ),
                    _connector="OR",
                ),
                name="both_null_or_both_not_null",
            ),
        ),
    ]
