from django.db import migrations

NOTIFICATION_TYPES = ['PRICE_OUT_OF_RANGE', 'OUT_OF_STOCK', 'LOW_STOCK']

# Matches today's implicit behavior: these surfaces (reports, stock counts, price
# approval) have always been manager-only, so nothing changes until a manager
# deliberately opens Settings and changes it.
DEFAULTS = {
    'MANAGER': True,
    'SELLER': False,
}


def seed_defaults(apps, schema_editor):
    NotificationSetting = apps.get_model('notifications', 'NotificationSetting')
    for notification_type in NOTIFICATION_TYPES:
        for role, enabled in DEFAULTS.items():
            NotificationSetting.objects.get_or_create(
                role=role, notification_type=notification_type, defaults={'enabled': enabled},
            )


def noop_reverse(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('notifications', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(seed_defaults, noop_reverse),
    ]
