# Generated by Django 5.2 on 2025-09-16 20:46

from django.db import migrations


def create_templates(apps, schema_editor):
    Template = apps.get_model('api', 'PersistentAgentTemplate')

    templates = [
        {
            "code": "competitor-intelligence-analyst",
            "display_name": "Competitor Intelligence Analyst",
            "tagline": "Monitors rivals, product launches, and pricing moves",
            "description": (
                "Stay ahead of market shifts with a dedicated analyst who aggregates press releases,"
                " product changelogs, and community chatter into a concise competitive brief."
            ),
            "charter": (
                "Continuously monitor top competitors for pricing changes, product updates,"
                " executive hires, and sentiment shifts. Summarize key findings, flag urgent risks,"
                " and recommend actions aligned with our go-to-market priorities."
            ),
            "base_schedule": "20 13 * * MON-FRI",
            "schedule_jitter_minutes": 25,
            "event_triggers": [
                {"type": "webhook", "name": "competitor-alert", "description": "Triggered by press release or RSS ingest"}
            ],
            "default_tools": [
                "mcp_brightdata_search_engine",
                "mcp_brightdata_scrape_as_markdown",
                "google_sheets-add-single-row"
            ],
            "recommended_contact_channel": "email",
            "category": "External Intel",
            "hero_image_path": "images/ai-directory/competitor-analyst.svg",
            "priority": 10,
        },
        {
            "code": "vendor-price-analyst",
            "display_name": "Vendor Price Analyst",
            "tagline": "Tracks supplier quotes and finds negotiation leverage",
            "description": (
                "Continuously compares contracted vendor pricing with public catalogs and tender feeds,"
                " surfacing opportunities to renegotiate or switch providers."
            ),
            "charter": (
                "Collect supplier quotes, monitor public catalogs, and highlight price changes above 3%."
                " Recommend negotiation tactics and surface alternative vendors with better SLAs."
            ),
            "base_schedule": "5 15 * * MON,THU",
            "schedule_jitter_minutes": 20,
            "event_triggers": [
                {"type": "webhook", "name": "new-invoice", "description": "Triggered when finance uploads a new invoice"}
            ],
            "default_tools": [
                "mcp_brightdata_scrape_as_markdown",
                "google_sheets-add-single-row",
                "google_drive-create-doc"
            ],
            "recommended_contact_channel": "email",
            "category": "Operations",
            "hero_image_path": "images/ai-directory/vendor-analyst.svg",
            "priority": 15,
        },
        {
            "code": "public-safety-scout",
            "display_name": "Public Safety Scout",
            "tagline": "Monitors crime and incident feeds around your offices",
            "description": (
                "Aggregates police blotters, 311 feeds, and transportation alerts near employee hubs"
                " so workplace teams can notify travelers and adjust security posture."
            ),
            "charter": (
                "Monitor city crime and incident feeds around our offices and travel hotspots."
                " Summarize notable risks, escalate high-severity incidents immediately, and"
                " maintain a running log for the workplace team."
            ),
            "base_schedule": "40 * * * *",
            "schedule_jitter_minutes": 10,
            "event_triggers": [
                {"type": "webhook", "name": "high-severity-incident", "description": "Pager triggered for violent or transit-stopping events"}
            ],
            "default_tools": [
                "mcp_brightdata_search_engine",
                "mcp_brightdata_scrape_as_markdown"
            ],
            "recommended_contact_channel": "sms",
            "category": "Risk & Compliance",
            "hero_image_path": "images/ai-directory/public-safety.svg",
            "priority": 20,
        },
        {
            "code": "team-standup-coordinator",
            "display_name": "Standup Coordinator",
            "tagline": "Collects blockers and ships the daily standup recap",
            "description": (
                "Automates daily standups by pulling updates from issue trackers, prompting stragglers,"
                " and delivering a tight summary to Slack and email."
            ),
            "charter": (
                "Coordinate the daily engineering standup. Remind contributors for updates, summarize"
                " completed work, upcoming tasks, and blockers, then distribute the recap to the team at 9:15am local."
            ),
            "base_schedule": "15 9 * * MON-FRI",
            "schedule_jitter_minutes": 8,
            "event_triggers": [
                {"type": "calendar", "name": "standup-meeting", "description": "Triggered when the standup calendar event begins"}
            ],
            "default_tools": [
                "slack-post-message",
                "slack-fetch-channel-history",
                "jira-search-issues"
            ],
            "recommended_contact_channel": "slack",
            "category": "Team Ops",
            "hero_image_path": "images/ai-directory/standup.svg",
            "priority": 30,
        },
        {
            "code": "incident-comms-scribe",
            "display_name": "Incident Comms Scribe",
            "tagline": "Captures status updates and keeps stakeholders aligned",
            "description": (
                "Records every incident update, drafts stakeholder emails, and ensures post-mortem materials"
                " have a clean timeline. Ideal for on-call rotations."
            ),
            "charter": (
                "During incidents, capture status updates from Slack and PagerDuty, prepare stakeholder"
                " summaries, and update the incident timeline document. Highlight missing action items after the event."
            ),
            "base_schedule": "0 * * * *",
            "schedule_jitter_minutes": 12,
            "event_triggers": [
                {"type": "pager", "name": "pagerduty-trigger", "description": "Runs immediately when a PagerDuty incident opens"}
            ],
            "default_tools": [
                "slack-post-message",
                "google_docs-append-text",
                "pagerduty-fetch-incident"
            ],
            "recommended_contact_channel": "email",
            "category": "Operations",
            "hero_image_path": "images/ai-directory/incident-scribe.svg",
            "priority": 40,
        },
        {
            "code": "sales-pipeline-whisperer",
            "display_name": "Pipeline Whisperer",
            "tagline": "Keeps your CRM healthy and nudges reps at the right time",
            "description": (
                "Surfaces stale deals, drafts follow-up emails, and syncs meeting notes back into the CRM"
                " while forecasting risk on key opportunities."
            ),
            "charter": (
                "Review the CRM pipeline daily, flag deals with no activity in 5 days, suggest next actions,"
                " and update opportunity fields based on meeting transcripts and emails."
            ),
            "base_schedule": "50 11 * * MON-FRI",
            "schedule_jitter_minutes": 18,
            "event_triggers": [
                {"type": "webhook", "name": "new-meeting-notes", "description": "Triggered when a call transcript is added"}
            ],
            "default_tools": [
                "salesforce-update-record",
                "google_drive-create-doc",
                "slack-post-message"
            ],
            "recommended_contact_channel": "email",
            "category": "Revenue",
            "hero_image_path": "images/ai-directory/pipeline.svg",
            "priority": 50,
        },
        {
            "code": "talent-sourcer",
            "display_name": "Talent Sourcer",
            "tagline": "Builds outreach lists and keeps recruiters in sync",
            "description": (
                "Finds candidates across public networks, drafts tailored outreach, and maintains a shared"
                " tracker with response rates for recruiting pods."
            ),
            "charter": (
                "Build and maintain a prospect list for priority roles, draft outreach sequences,"
                " and summarize weekly funnel metrics for the recruiting team."
            ),
            "base_schedule": "30 14 * * TUE",
            "schedule_jitter_minutes": 22,
            "event_triggers": [
                {"type": "webhook", "name": "new-role-opened", "description": "Triggered when a new job requisition is approved"}
            ],
            "default_tools": [
                "greenhouse-create-candidate",
                "google_sheets-add-single-row",
                "slack-post-message"
            ],
            "recommended_contact_channel": "email",
            "category": "People",
            "hero_image_path": "images/ai-directory/talent.svg",
            "priority": 60,
        },
        {
            "code": "employee-onboarding-concierge",
            "display_name": "Onboarding Concierge",
            "tagline": "Welcomes new hires and keeps the checklist moving",
            "description": (
                "Guides new teammates through onboarding by scheduling orientation, collecting paperwork,"
                " and nudging stakeholders when tasks stall."
            ),
            "charter": (
                "Orchestrate the onboarding journey for each new hire. Send welcome notes, confirm"
                " equipment requests, schedule orientation sessions, and flag overdue checklist items."
            ),
            "base_schedule": "0 16 * * MON-FRI",
            "schedule_jitter_minutes": 15,
            "event_triggers": [
                {"type": "webhook", "name": "new-employee", "description": "Triggered when HRIS marks an employee as hired"}
            ],
            "default_tools": [
                "slack-post-message",
                "google_calendar-create-event",
                "google_sheets-add-single-row"
            ],
            "recommended_contact_channel": "email",
            "category": "People",
            "hero_image_path": "images/ai-directory/onboarding.svg",
            "priority": 70,
        },
        {
            "code": "compliance-audit-sentinel",
            "display_name": "Compliance Sentinel",
            "tagline": "Audits policies and alerts owners when controls drift",
            "description": (
                "Keeps SOC2 and ISO tasks on track by diffing policy repos, checking evidence folders,"
                " and reminding control owners ahead of audits."
            ),
            "charter": (
                "Review compliance control evidence weekly, flag missing documentation,"
                " and summarize control status for the security lead."
            ),
            "base_schedule": "10 12 * * MON",
            "schedule_jitter_minutes": 30,
            "event_triggers": [
                {"type": "webhook", "name": "audit-window-open", "description": "Triggered 30 days before external audits"}
            ],
            "default_tools": [
                "google_drive-create-doc",
                "mcp_brightdata_search_engine"
            ],
            "recommended_contact_channel": "email",
            "category": "Risk & Compliance",
            "hero_image_path": "images/ai-directory/compliance.svg",
            "priority": 80,
        },
        {
            "code": "customer-health-monitor",
            "display_name": "Customer Health Monitor",
            "tagline": "Surfaces churn risk and expansion signals",
            "description": (
                "Combines product usage, support tickets, and sentiment feeds to highlight accounts"
                " needing attention and celebrate expansion opportunities."
            ),
            "charter": (
                "Review customer health metrics daily, alert the success manager when usage drops,"
                " and compile weekly executive summaries with risk and expansion signals."
            ),
            "base_schedule": "5 10 * * MON-FRI",
            "schedule_jitter_minutes": 12,
            "event_triggers": [
                {"type": "webhook", "name": "support-ticket-created", "description": "Triggered when critical support tickets open"}
            ],
            "default_tools": [
                "zendesk-create-comment",
                "slack-post-message",
                "google_sheets-add-single-row"
            ],
            "recommended_contact_channel": "email",
            "category": "Revenue",
            "hero_image_path": "images/ai-directory/customer-health.svg",
            "priority": 90,
        },
    ]

    for entry in templates:
        Template.objects.update_or_create(code=entry["code"], defaults=entry)


def delete_templates(apps, schema_editor):
    Template = apps.get_model('api', 'PersistentAgentTemplate')
    codes = [
        "competitor-intelligence-analyst",
        "vendor-price-analyst",
        "public-safety-scout",
        "team-standup-coordinator",
        "incident-comms-scribe",
        "sales-pipeline-whisperer",
        "talent-sourcer",
        "employee-onboarding-concierge",
        "compliance-audit-sentinel",
        "customer-health-monitor",
    ]
    Template.objects.filter(code__in=codes).delete()


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0130_persistentagenttemplate'),
    ]

    operations = [
        migrations.RunPython(create_templates, delete_templates),
    ]
