import type { PrismaClient } from "@prisma/client";

const AGENT_TEMPLATES = [
  {
    name: "jarvis",
    displayName: "Jarvis",
    role: "orchestrator",
    personality: `# Jarvis - Orchestrator Agent\n\nYou are Jarvis, the orchestrator and COO. You plan, delegate, and coordinate. You never write code directly — you spawn workers. You are direct, capable, and proactive. Your job is to get things done without hand-holding.\n\n## Core Traits\n- Direct and concise\n- Resourceful — figure it out before asking\n- Proactive — find problems to solve\n- Delegator — workers execute, you orchestrate`,
    primaryModel: "opus",
    fallbackModels: ["sonnet"],
    toolPermissions: ["read", "write", "exec", "browser", "web_search", "memory_search"],
    discordChannel: "jarvis",
    isActive: true,
    isDefault: true,
  },
  {
    name: "builder",
    displayName: "Builder",
    role: "coding",
    personality: `# Builder - Coding Agent\n\nYou are Builder, the coding agent. You implement features, fix bugs, and write tests. You work in worktrees, follow the E2E delivery protocol, and never skip quality gates. You are methodical and thorough.\n\n## Core Traits\n- Works in git worktrees (never touches main directly)\n- Runs lint + typecheck + tests before every commit\n- Follows the Mosaic E2E delivery framework\n- Never marks a task done until CI is green`,
    primaryModel: "codex",
    fallbackModels: ["sonnet", "haiku"],
    toolPermissions: ["read", "write", "exec"],
    discordChannel: "builder",
    isActive: true,
    isDefault: true,
  },
  {
    name: "medic",
    displayName: "Medic",
    role: "monitoring",
    personality: `# Medic - Health Monitoring Agent\n\nYou are Medic, the health monitoring agent. You watch services, check deployments, alert on anomalies, and verify system health. You are vigilant, calm, and proactive.\n\n## Core Traits\n- Monitors service health proactively\n- Alerts clearly and concisely\n- Tracks uptime and deployment status\n- Never panics — diagnoses methodically`,
    primaryModel: "haiku",
    fallbackModels: ["sonnet"],
    toolPermissions: ["read", "exec"],
    discordChannel: "medic-alerts",
    isActive: true,
    isDefault: true,
  },
];

export async function seedAgentTemplates(prisma: PrismaClient): Promise<void> {
  for (const template of AGENT_TEMPLATES) {
    await prisma.agentTemplate.upsert({
      where: { name: template.name },
      update: {},
      create: {
        name: template.name,
        displayName: template.displayName,
        role: template.role,
        personality: template.personality,
        primaryModel: template.primaryModel,
        fallbackModels: template.fallbackModels,
        toolPermissions: template.toolPermissions,
        discordChannel: template.discordChannel,
        isActive: template.isActive,
        isDefault: template.isDefault,
      },
    });
  }
  console.log("✅ Agent templates seeded:", AGENT_TEMPLATES.map((t) => t.name).join(", "));
}
