# Generated by Django 5.0.3 on 2025-09-17 03:49

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


class Migration(migrations.Migration):

    dependencies = [
        ('pxy_bots', '0006_telegramconversation_telegrammessage'),
        ('pxy_langchain', '0003_aiassistant_neo4j_profile_aiassistant_uses_graph'),
    ]

    operations = [
        migrations.CreateModel(
            name='Connection',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=120, unique=True)),
                ('base_url', models.CharField(help_text='e.g. https://api.example.com', max_length=500)),
                ('path_default', models.CharField(blank=True, default='', help_text='Optional default path, e.g. /bots/route', max_length=300)),
                ('auth_type', models.CharField(choices=[('none', 'None'), ('bearer', 'Bearer token'), ('api_key', 'API key (in header)'), ('basic', 'Basic user:pass')], default='none', max_length=20)),
                ('auth_value', models.CharField(blank=True, default='', help_text='token | key | user:pass', max_length=500)),
                ('headers_json', models.TextField(blank=True, default='', help_text='Extra headers as JSON object')),
                ('timeout_s', models.PositiveIntegerField(default=4, validators=[django.core.validators.MinValueValidator(1)])),
                ('allowed_hosts', models.CharField(blank=True, default='127.0.0.1,localhost,app.polisplexity.tech', help_text='Comma-separated host allowlist for safety.', max_length=800)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.AlterModelOptions(
            name='telegrambot',
            options={'ordering': ['name']},
        ),
        migrations.AlterModelOptions(
            name='telegramconversation',
            options={'ordering': ['-started_at']},
        ),
        migrations.AlterModelOptions(
            name='telegrammessage',
            options={'ordering': ['timestamp', 'id']},
        ),
        migrations.AddField(
            model_name='telegrambot',
            name='created_at',
            field=models.DateTimeField(default=django.utils.timezone.now, editable=False),
        ),
        migrations.AddField(
            model_name='telegrambot',
            name='updated_at',
            field=models.DateTimeField(auto_now=True),
        ),
        migrations.AlterField(
            model_name='telegrambot',
            name='assistant',
            field=models.ForeignKey(help_text='LangChain AI assistant associated with this bot.', on_delete=django.db.models.deletion.CASCADE, related_name='telegram_bots', to='pxy_langchain.aiassistant'),
        ),
        migrations.AlterField(
            model_name='telegrambot',
            name='is_active',
            field=models.BooleanField(default=True, help_text='If off, webhook can be refused.'),
        ),
        migrations.CreateModel(
            name='CommandRoute',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('trigger', models.CharField(choices=[('message', 'Message (no command)'), ('text_command', 'Text command (/cmd)'), ('callback', 'Callback')], default='message', max_length=20)),
                ('command_name', models.CharField(blank=True, help_text="Without leading '/'. Leave blank for default of that trigger.", max_length=80, null=True)),
                ('path', models.CharField(blank=True, default='', help_text='Overrides connection.path_default if set', max_length=300)),
                ('enabled', models.BooleanField(default=True)),
                ('priority', models.PositiveIntegerField(default=100, help_text='Lower runs first')),
                ('note', models.CharField(blank=True, default='', max_length=240)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('bot', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='routes', to='pxy_bots.telegrambot')),
                ('connection', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='routes', to='pxy_bots.connection')),
            ],
            options={
                'ordering': ['priority', 'id'],
                'indexes': [models.Index(fields=['bot', 'trigger', 'command_name', 'enabled', 'priority'], name='pxy_bots_co_bot_id_fd0f4c_idx')],
            },
        ),
    ]
