# Generated by Django 5.2.7 on 2025-10-13 11:23

import django.db.models.deletion
import shortuuid.django_fields
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="IssueCaptureSettings",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "enabled",
                    models.BooleanField(
                        default=True, help_text="Enable issue capture floating button for staff/superusers"
                    ),
                ),
                (
                    "github_repo",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="GitHub repository in format: owner/repo (e.g., 'octocat/Hello-World')",
                        max_length=255,
                    ),
                ),
                (
                    "github_api_key",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="GitHub Personal Access Token with repo access",
                        max_length=255,
                    ),
                ),
                (
                    "github_label",
                    models.CharField(
                        default="issue-capture", help_text="Label to apply to created GitHub issues", max_length=50
                    ),
                ),
                (
                    "llm_api_key",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="API key for LLM provider (OpenAI, Anthropic, etc.). Set via environment for production.",
                        max_length=255,
                    ),
                ),
                (
                    "llm_model",
                    models.CharField(
                        default="gpt-4o-mini",
                        help_text="LLM model identifier (e.g., gpt-4o-mini, claude-3-5-sonnet-20241022, ollama/llama3)",
                        max_length=100,
                    ),
                ),
                (
                    "llm_enabled",
                    models.BooleanField(default=True, help_text="Enable LLM-powered issue enhancement and generation"),
                ),
                (
                    "llm_temperature",
                    models.FloatField(
                        default=0.7, help_text="Temperature for LLM generation (0.0-1.0, higher = more creative)"
                    ),
                ),
                (
                    "llm_max_tokens",
                    models.PositiveIntegerField(
                        default=2000, help_text="Maximum tokens for LLM generation (higher = longer responses)"
                    ),
                ),
            ],
            options={
                "verbose_name": "Issue Capture Settings",
            },
        ),
        migrations.CreateModel(
            name="IssueTemplate",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "name",
                    models.CharField(
                        choices=[
                            ("bug", "Bug Report"),
                            ("feature", "Feature Request"),
                            ("task", "Task"),
                            ("enhancement", "Enhancement"),
                            ("question", "Question"),
                        ],
                        max_length=100,
                        unique=True,
                    ),
                ),
                ("display_name", models.CharField(help_text="Human-friendly name", max_length=100)),
                ("description", models.TextField(help_text="Description of when to use this template")),
                (
                    "discovery_questions",
                    models.JSONField(
                        default=list, help_text="List of questions to ask during conversation to gather context"
                    ),
                ),
                (
                    "required_context",
                    models.JSONField(
                        default=list,
                        help_text="List of context fields that should be gathered (e.g., 'steps_to_reproduce', 'expected_behavior')",
                    ),
                ),
                (
                    "max_conversation_turns",
                    models.PositiveIntegerField(
                        default=10, help_text="Maximum number of conversation turns before auto-generating issue"
                    ),
                ),
                ("discovery_prompt", models.TextField(help_text="System prompt for conducting discovery conversation")),
                (
                    "generation_prompt",
                    models.TextField(help_text="System prompt for generating final issue from conversation context"),
                ),
                (
                    "quick_enhancement_prompt",
                    models.TextField(help_text="Prompt for quick one-shot enhancement without conversation"),
                ),
                (
                    "default_labels",
                    models.CharField(
                        blank=True,
                        help_text="Comma-separated list of default GitHub labels for this issue type",
                        max_length=200,
                    ),
                ),
                ("is_active", models.BooleanField(default=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "Issue Template",
                "verbose_name_plural": "Issue Templates",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="IssueConversation",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "conversation_state",
                    models.CharField(
                        choices=[
                            ("discovering", "Discovering Context"),
                            ("clarifying", "Clarifying Details"),
                            ("summarizing", "Summarizing Information"),
                            ("ready", "Ready for Generation"),
                            ("complete", "Conversation Complete"),
                        ],
                        default="discovering",
                        max_length=20,
                    ),
                ),
                (
                    "conversation_id",
                    shortuuid.django_fields.ShortUUIDField(
                        alphabet=None,
                        editable=False,
                        help_text="Unique identifier for this conversation",
                        length=22,
                        max_length=22,
                        prefix="",
                        unique=True,
                    ),
                ),
                (
                    "messages",
                    models.JSONField(
                        default=list, help_text="List of conversation messages with role (user/assistant) and content"
                    ),
                ),
                (
                    "context_gathered",
                    models.JSONField(default=dict, help_text="Extracted context information organized by type"),
                ),
                (
                    "initial_description",
                    models.TextField(help_text="User's initial description that started the conversation"),
                ),
                (
                    "turns_count",
                    models.PositiveIntegerField(default=0, help_text="Number of conversation turns completed"),
                ),
                (
                    "ready_for_generation",
                    models.BooleanField(
                        default=False, help_text="Whether conversation has gathered enough context for issue generation"
                    ),
                ),
                (
                    "user_abandoned",
                    models.BooleanField(
                        default=False, help_text="Whether user abandoned the conversation before completion"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("last_activity_at", models.DateTimeField(auto_now=True)),
                ("generated_title", models.CharField(blank=True, max_length=200)),
                ("generated_description", models.TextField(blank=True)),
                ("generated_labels", models.CharField(blank=True, max_length=200)),
                (
                    "confidence_score",
                    models.FloatField(
                        blank=True, help_text="AI confidence in the generated content (0.0 to 1.0)", null=True
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        help_text="User who started this conversation",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="issue_conversations",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        help_text="Template being used for this conversation",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="conversations",
                        to="django_issue_capture.issuetemplate",
                    ),
                ),
            ],
            options={
                "verbose_name": "Issue Conversation",
                "verbose_name_plural": "Issue Conversations",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="Issue",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "short_uuid",
                    shortuuid.django_fields.ShortUUIDField(
                        alphabet=None, editable=False, length=22, max_length=22, prefix="", unique=True
                    ),
                ),
                ("title", models.CharField(max_length=200)),
                ("description", models.TextField()),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("open", "Open"),
                            ("in_progress", "In Progress"),
                            ("resolved", "Resolved"),
                            ("closed", "Closed"),
                        ],
                        default="open",
                        max_length=20,
                    ),
                ),
                (
                    "priority",
                    models.CharField(
                        choices=[("low", "Low"), ("medium", "Medium"), ("high", "High"), ("urgent", "Urgent")],
                        default="medium",
                        max_length=10,
                    ),
                ),
                ("reported_url", models.URLField(help_text="URL where the issue was reported from")),
                ("user_agent", models.TextField(blank=True, help_text="Browser user agent string")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("payload", models.JSONField(blank=True, default=dict, help_text="Additional issue metadata")),
                (
                    "acceptance_criteria",
                    models.TextField(
                        blank=True, default="", help_text="AI-generated acceptance criteria for the issue"
                    ),
                ),
                (
                    "technical_specifications",
                    models.TextField(
                        blank=True,
                        default="",
                        help_text="AI-generated technical specifications and implementation details",
                    ),
                ),
                (
                    "implementation_hints",
                    models.TextField(
                        blank=True, default="", help_text="AI-generated hints and suggestions for implementation"
                    ),
                ),
                (
                    "estimated_complexity",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="AI-estimated complexity level (low, medium, high, very-high)",
                        max_length=20,
                    ),
                ),
                (
                    "suggested_labels",
                    models.TextField(blank=True, default="", help_text="AI-suggested GitHub labels (comma-separated)"),
                ),
                (
                    "creation_mode",
                    models.CharField(
                        choices=[
                            ("form", "Standard Form"),
                            ("chat", "AI Conversation"),
                            ("quick", "Quick AI Enhancement"),
                        ],
                        default="form",
                        help_text="How this issue was created",
                        max_length=10,
                    ),
                ),
                (
                    "has_llm_conversation",
                    models.BooleanField(
                        default=False, help_text="Whether this issue was created through LLM conversation"
                    ),
                ),
                (
                    "llm_confidence_score",
                    models.FloatField(
                        blank=True, help_text="AI confidence score in the generated content (0.0 to 1.0)", null=True
                    ),
                ),
                (
                    "conversation_summary",
                    models.TextField(blank=True, default="", help_text="Summary of key insights from the conversation"),
                ),
                ("github_url", models.URLField(blank=True, help_text="URL of the GitHub issue if promoted")),
                (
                    "github_issue_number",
                    models.PositiveIntegerField(blank=True, help_text="GitHub issue number if promoted", null=True),
                ),
                (
                    "github_promoted_at",
                    models.DateTimeField(blank=True, help_text="When the issue was promoted to GitHub", null=True),
                ),
                (
                    "assigned_to",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="assigned_issues",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "github_promoted_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="User who promoted the issue to GitHub",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="promoted_issues",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "reported_by",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="reported_issues",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "conversation",
                    models.OneToOneField(
                        blank=True,
                        help_text="Conversation that led to this issue (if created via chat)",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="created_issue",
                        to="django_issue_capture.issueconversation",
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        blank=True,
                        help_text="Template used for this issue (if any)",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="issues",
                        to="django_issue_capture.issuetemplate",
                    ),
                ),
            ],
            options={
                "verbose_name": "Issue",
                "verbose_name_plural": "Issues",
                "ordering": ["-created_at"],
            },
        ),
    ]
