# Generated by Django 5.0.1 on 2024-01-12 19:02

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='LocalActor',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('private_key', models.TextField(blank=True, editable=False)),
                ('public_key', models.TextField(blank=True, editable=False)),
                ('actor_type', models.CharField(choices=[('P', 'Person'), ('S', 'Service')], default='P', max_length=1)),
                ('preferred_username', models.SlugField(max_length=255)),
                ('domain', models.CharField(max_length=255)),
                ('name', models.CharField(max_length=255)),
                ('summary', models.TextField(blank=True)),
                ('icon', models.ImageField(blank=True, null=True, upload_to='actor-media')),
                ('image', models.ImageField(blank=True, null=True, upload_to='actor-media')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='Follower',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('follow_date', models.DateTimeField(auto_now=True)),
                ('following', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='activitypub.localactor')),
            ],
        ),
        migrations.CreateModel(
            name='RemoteActor',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('username', models.CharField(max_length=255)),
                ('domain', models.CharField(max_length=255)),
                ('url', models.URLField(db_index=True, unique=True)),
                ('profile', models.JSONField(blank=True, default=dict)),
                ('following', models.ManyToManyField(related_name='following', through='activitypub.Follower', to='activitypub.localactor')),
            ],
        ),
        migrations.CreateModel(
            name='Note',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('published_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('content', models.TextField()),
                ('content_url', models.URLField(db_index=True)),
                ('local_actor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='activitypub.localactor')),
                ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='activitypub.note', verbose_name='parent')),
                ('announces', models.ManyToManyField(blank=True, related_name='announces', to='activitypub.remoteactor')),
                ('likes', models.ManyToManyField(blank=True, related_name='likes', to='activitypub.remoteactor')),
                ('remote_actor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='activitypub.remoteactor')),
            ],
        ),
        migrations.AddField(
            model_name='localactor',
            name='followers',
            field=models.ManyToManyField(related_name='followers', through='activitypub.Follower', to='activitypub.remoteactor'),
        ),
        migrations.AddField(
            model_name='follower',
            name='remote_actor',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='activitypub.remoteactor'),
        ),
        migrations.AddIndex(
            model_name='remoteactor',
            index=models.Index(fields=['username', 'domain'], name='activitypub_remote_actor_idx'),
        ),
        migrations.AddIndex(
            model_name='note',
            index=models.Index(fields=['local_actor', 'published_at'], name='activitypub_notes_by_date_idx'),
        ),
        migrations.AddIndex(
            model_name='localactor',
            index=models.Index(fields=['preferred_username', 'domain'], name='activitypub_local_actor_idx'),
        ),
        migrations.AddIndex(
            model_name='follower',
            index=models.Index(fields=['following', 'follow_date'], name='activitypub_followers_date_idx'),
        ),
        migrations.AddConstraint(
            model_name='follower',
            constraint=models.UniqueConstraint(fields=('remote_actor', 'following'), name='activitypub_unique_followers'),
        ),
    ]
