# Generated by Django 5.2.7 on 2026-02-19 08:56

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


class Migration(migrations.Migration):

    dependencies = [
        ('base', '0005_newslettersystemsettings_newslettertemplatesettings'),
    ]

    operations = [
        migrations.CreateModel(
            name='OneClickUnsubscribeAudit',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('token_hash', models.CharField(db_index=True, max_length=64, unique=True)),
                ('subscriber_id', models.CharField(blank=True, max_length=128)),
                ('list_id', models.CharField(blank=True, max_length=128)),
                ('site_id', models.CharField(blank=True, max_length=128)),
                ('campaign_id', models.CharField(blank=True, max_length=128)),
                ('status', models.CharField(blank=True, max_length=32)),
                ('response_status', models.PositiveIntegerField(blank=True, null=True)),
                ('response_payload', models.JSONField(blank=True, default=dict)),
                ('error_message', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('processed_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='member_center_one_click_unsubscribe_path',
            field=models.CharField(blank=True, default='/api/subscriptions/unsubscribe', max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='one_click_endpoint_path',
            field=models.CharField(blank=True, default='/u/unsubscribe', max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='one_click_token_secret',
            field=models.CharField(blank=True, help_text='One-click token 簽章 secret；留空則使用 Django SECRET_KEY。', max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='one_click_token_ttl_seconds',
            field=models.PositiveIntegerField(default=2592000),
        ),
        migrations.CreateModel(
            name='NewsletterCampaign',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=255)),
                ('list_id', models.CharField(blank=True, max_length=128)),
                ('subject_template', models.CharField(max_length=255)),
                ('html_template', models.TextField()),
                ('text_template', models.TextField(blank=True)),
                ('status', models.CharField(choices=[('draft', 'Draft'), ('scheduled', 'Scheduled'), ('sending', 'Sending'), ('sent', 'Sent'), ('failed', 'Failed')], default='draft', max_length=16)),
                ('scheduled_at', models.DateTimeField(blank=True, null=True)),
                ('sent_at', models.DateTimeField(blank=True, null=True)),
                ('last_error', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='member_center_subscriptions_path',
            field=models.CharField(blank=True, default='/newsletter/subscriptions', max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='member_center_oauth_token_path',
            field=models.CharField(blank=True, default='/oauth/token', max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='member_center_oauth_client_id',
            field=models.CharField(blank=True, max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='member_center_oauth_client_secret',
            field=models.TextField(blank=True),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='member_center_oauth_scope',
            field=models.CharField(blank=True, default='newsletter:list.read', max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='member_center_oauth_audience',
            field=models.CharField(blank=True, max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='send_engine_send_jobs_path',
            field=models.CharField(blank=True, default='/api/send-jobs', max_length=255),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='send_engine_retry_interval_seconds',
            field=models.PositiveIntegerField(default=300),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='send_engine_retry_max_attempts',
            field=models.PositiveIntegerField(default=3),
        ),
        migrations.AddField(
            model_name='newslettersystemsettings',
            name='site_base_url',
            field=models.URLField(blank=True, help_text='排程發送使用的站台網址（例如 https://news.example.com）。'),
        ),
        migrations.CreateModel(
            name='NewsletterDispatchRecord',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('subscriber_id', models.CharField(blank=True, max_length=128)),
                ('email', models.EmailField(blank=True, max_length=254)),
                ('status', models.CharField(blank=True, max_length=32)),
                ('retry_count', models.PositiveIntegerField(default=0)),
                ('next_retry_at', models.DateTimeField(blank=True, null=True)),
                ('response_status', models.PositiveIntegerField(blank=True, null=True)),
                ('response_payload', models.JSONField(blank=True, default=dict)),
                ('error_message', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('campaign', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='dispatch_records', to='base.newslettercampaign')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
    ]
