"""
Migration 0010 — Add binary tree fields to DistributorID.

Every DistributorID gains:
  binary_parent_distributor — FK to self (their parent in the binary tree)
  binary_position           — 'LEFT' | 'RIGHT' (which slot under the parent)

Both are nullable so existing rows are unaffected; the backfill_binary_tree
management command populates them from sponsor history.
"""

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('distributor', '0009_remove_unique_user_product_distributorid'),
    ]

    operations = [
        migrations.AddField(
            model_name='distributorid',
            name='binary_parent_distributor',
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name='binary_children',
                to='distributor.distributorid',
                verbose_name='Binary Parent',
            ),
        ),
        migrations.AddField(
            model_name='distributorid',
            name='binary_position',
            field=models.CharField(
                blank=True,
                choices=[('LEFT', 'Left'), ('RIGHT', 'Right')],
                db_index=True,
                max_length=5,
                null=True,
                verbose_name='Binary Position',
            ),
        ),
        migrations.AddIndex(
            model_name='distributorid',
            index=models.Index(
                fields=['binary_parent_distributor', 'binary_position'],
                name='dist_binary_parent_pos_idx',
            ),
        ),
    ]
