# Generated by Django 5.2.7 on 2026-03-14 06:16

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('account', '0032_notification'),
        ('fileman', '0012_remove_filemanager_fileman_fil_group_i_c1c47d_idx_and_more'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='ShortLink',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('modified', models.DateTimeField(auto_now=True)),
                ('code', models.CharField(db_index=True, max_length=10, unique=True)),
                ('url', models.TextField(blank=True, default='', help_text='Destination URL (empty when using file-only link)')),
                ('source', models.CharField(blank=True, db_index=True, default='', help_text='Traceability tag: sms, email, fileman, etc.', max_length=50)),
                ('hit_count', models.IntegerField(default=0)),
                ('expires_at', models.DateTimeField(blank=True, db_index=True, help_text='When this link expires (null = never)', null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('track_clicks', models.BooleanField(default=False, help_text='Log each visit with IP, user-agent, referer')),
                ('resolve_file', models.BooleanField(default=True, help_text='True = resolve file download URL dynamically per click; False = use stored url')),
                ('bot_passthrough', models.BooleanField(default=False, help_text='True = skip bot detection and OG preview, always redirect')),
                ('metadata', models.JSONField(blank=True, default=dict, help_text='OG/meta tags and scraped preview cache')),
                ('file', models.ForeignKey(blank=True, default=None, help_text='Optional linked file for file-sharing shortlinks', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='shortlinks', to='fileman.file')),
                ('group', models.ForeignKey(blank=True, default=None, help_text='Group that owns this short link', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='shortlinks', to='account.group')),
                ('user', models.ForeignKey(blank=True, default=None, help_text='User who created this short link', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='shortlinks', to=settings.AUTH_USER_MODEL)),
            ],
            bases=(models.Model, mojo.models.rest.MojoModel),
        ),
        migrations.CreateModel(
            name='ShortLinkClick',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('ip', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.TextField(blank=True, default='')),
                ('referer', models.TextField(blank=True, default='')),
                ('is_bot', models.BooleanField(default=False)),
                ('shortlink', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='clicks', to='shortlink.shortlink')),
            ],
            bases=(models.Model, mojo.models.rest.MojoModel),
        ),
        migrations.AddIndex(
            model_name='shortlink',
            index=models.Index(fields=['source', 'is_active'], name='shortlink_s_source_41730f_idx'),
        ),
        migrations.AddIndex(
            model_name='shortlink',
            index=models.Index(fields=['expires_at', 'is_active'], name='shortlink_s_expires_d79248_idx'),
        ),
        migrations.AddIndex(
            model_name='shortlink',
            index=models.Index(fields=['user', 'is_active'], name='shortlink_s_user_id_339dcd_idx'),
        ),
        migrations.AddIndex(
            model_name='shortlink',
            index=models.Index(fields=['group', 'is_active'], name='shortlink_s_group_i_4bcb8a_idx'),
        ),
        migrations.AddIndex(
            model_name='shortlinkclick',
            index=models.Index(fields=['shortlink', 'created'], name='shortlink_s_shortli_7d9c3a_idx'),
        ),
    ]
