# Generated by Django 5.1.4 on 2025-02-04 11:50

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


class Migration(migrations.Migration):

    dependencies = [
        ('customers', '0001_initial'),
        ('system_settings', '0006_alter_accounttype_sequence'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='accounttype',
            name='default_group_type',
        ),
        migrations.RemoveField(
            model_name='accounttype',
            name='group_configurations',
        ),
        migrations.AddField(
            model_name='accounttype',
            name='default_group',
            field=models.CharField(default='Test', help_text='Default MT5 group if no group configuration exists', max_length=100),
            preserve_default=False,
        ),
        migrations.CreateModel(
            name='GroupConfiguration',
            fields=[
                ('id', models.AutoField(editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.IntegerField(blank=True, null=True)),
                ('updated_by', models.IntegerField(blank=True, null=True)),
                ('country', models.CharField(default='*', help_text="Country code or '*' for default configuration", max_length=2)),
                ('groups', models.JSONField(default=dict, help_text='\n        Group paths configuration. Example:\n        {\n            "default": "\\MT5_LIVE\\Standard",\n            "swap_free": "\\MT5_LIVE\\Standard_SwapFree",\n            "bonus": "\\MT5_LIVE\\Standard_Bonus",\n            "bonus_swap_free": "\\MT5_LIVE\\Standard_Bonus_SwapFree",\n            "markup": "\\MT5_LIVE\\Standard_Markup",\n            "ib": "\\MT5_LIVE\\Standard_IB"\n        }\n        The presence of a key (e.g., "swap_free") indicates that feature is allowed.\n        ')),
                ('account_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='group_configs', to='system_settings.accounttype')),
            ],
            options={
                'verbose_name': 'Group Configuration',
                'verbose_name_plural': 'Group Configurations',
                'db_table': 'group_configurations',
                'permissions': [('view_group_configuration', 'Can view group configuration'), ('add_group_configuration', 'Can add group configuration'), ('change_group_configuration', 'Can change group configuration'), ('delete_group_configuration', 'Can delete group configuration')],
                'unique_together': {('account_type', 'country')},
            },
        ),
        migrations.CreateModel(
            name='IBCustomGroupConfiguration',
            fields=[
                ('id', models.AutoField(editable=False, primary_key=True, serialize=False)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('created_by', models.IntegerField(blank=True, null=True)),
                ('updated_by', models.IntegerField(blank=True, null=True)),
                ('groups', models.JSONField(default=dict, help_text='\n        Custom group paths for this IB\'s clients. Example:\n        {\n            "default": "\\MT5_LIVE\\Standard_IB_123",\n            "swap_free": "\\MT5_LIVE\\Standard_IB_123_SwapFree",\n            "bonus": "\\MT5_LIVE\\Standard_IB_123_Bonus",\n            "bonus_swap_free": "\\MT5_LIVE\\Standard_IB_123_Bonus_SwapFree"\n        }\n        Only need to specify the groups that are different from the base configuration.\n        Features (swap_free, bonus, etc.) are allowed if their corresponding group paths exist.\n        ')),
                ('group_config', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ib_custom_configs', to='system_settings.groupconfiguration')),
                ('ib', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='custom_group_configs', to='customers.customer')),
            ],
            options={
                'verbose_name': 'IB Custom Group Configuration',
                'verbose_name_plural': 'IB Custom Group Configurations',
                'db_table': 'ib_custom_group_configurations',
                'permissions': [('view_ib_custom_group', 'Can view IB custom group configuration'), ('add_ib_custom_group', 'Can add IB custom group configuration'), ('change_ib_custom_group', 'Can change IB custom group configuration'), ('delete_ib_custom_group', 'Can delete IB custom group configuration')],
                'unique_together': {('group_config', 'ib')},
            },
        ),
    ]
