# Generated by Django 5.1.12 on 2025-09-24 09:28

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


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0007_blob_size_compressed'),
    ]

    operations = [
        migrations.CreateModel(
            name='Channel',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, help_text='primary key for the record as UUID', primary_key=True, serialize=False, verbose_name='id')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='date and time at which a record was created', verbose_name='created on')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='date and time at which a record was last updated', verbose_name='updated on')),
                ('name', models.CharField(help_text='Human-readable name for this channel', max_length=255, verbose_name='name')),
                ('type', models.CharField(default='mta', help_text='Type of channel', max_length=255, verbose_name='type')),
                ('settings', models.JSONField(blank=True, default=dict, help_text='Channel-specific configuration settings', verbose_name='settings')),
                ('mailbox', models.ForeignKey(blank=True, help_text='Mailbox that receives messages from this channel', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='channels', to='core.mailbox')),
                ('maildomain', models.ForeignKey(blank=True, help_text='Mail domain that owns this channel', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='channels', to='core.maildomain')),
            ],
            options={
                'verbose_name': 'channel',
                'verbose_name_plural': 'channels',
                'db_table': 'messages_channel',
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='message',
            name='channel',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='messages', to='core.channel'),
        ),
        migrations.AddConstraint(
            model_name='channel',
            constraint=models.CheckConstraint(condition=models.Q(('mailbox__isnull', False), ('maildomain__isnull', False), _connector='XOR'), name='channel_has_target'),
        ),
    ]
