import { NextResponse } from "next/server";

// Pre-built bulletproof templates for clinics
export async function GET() {
  const templates = [
    {
      id: "appointment-reminder",
      name: "Appointment Reminder",
      description: "Full confirmation flow with reschedule & cancel options",
      category: "Booking",
      icon: "📅",
      color: "#0284c7",
      nodeCount: 8,
      nodes: [
        { id:"s1", type:"start",    position:{x:60,y:200},   data:{kind:"start",    label:"New Booking",       content:"booking_created"} },
        { id:"m1", type:"message",  position:{x:360,y:200},  data:{kind:"message",  label:"Booking Confirmed", content:"Hi {{name}}! 🎉\n\nYour *{{treatment}}* appointment is confirmed!\n\n📅 *Date:* {{date}}\n🕐 *Time:* {{time}}\n🏥 *Location:* {{clinic}}\n\nWe're so excited to see you! 💙"} },
        { id:"b1", type:"buttons",  position:{x:700,y:200},  data:{kind:"buttons",  label:"Confirm Options", content:"Can you confirm your attendance, {{name}}?", buttons:[{id:"yes",label:"✅ Yes, I'll be there",text:"✅ Yes, I'll be there"},{id:"reschedule",label:"📅 Reschedule",text:"📅 Reschedule"},{id:"cancel",label:"❌ Cancel",text:"❌ Cancel"}]} },
        { id:"m2", type:"message",  position:{x:1080,y:60},  data:{kind:"message",  label:"Confirmed! 🎉",    content:"Wonderful! ✅ You're all set {{name}}!\n\nRemember to arrive *10 minutes early* and bring your ID.\n\nSee you on {{date}} at {{time}}! 🙏"} },
        { id:"a1", type:"ai_response", position:{x:1080,y:240}, data:{kind:"ai_response", label:"Reschedule Handler", aiSystemPrompt:"You are a warm assistant at {{clinic}}. {{name}} wants to reschedule their {{treatment}} on {{date}}. Acknowledge kindly, express that it's no problem at all, and ask them to share 2-3 preferred dates/times. Keep it under 3 sentences."} },
        { id:"m3", type:"message",  position:{x:1080,y:420}, data:{kind:"message",  label:"Cancel Confirmed",  content:"We're sorry to hear that, {{name}} 😢\n\nYour appointment has been cancelled. We hope to see you soon!\n\nWould you like to rebook in the future? Just message us anytime 💙"} },
        { id:"w1", type:"wait",     position:{x:1400,y:60},  data:{kind:"wait",     label:"Wait 1 Day",        delayMinutes:1440} },
        { id:"e1", type:"end",      position:{x:1700,y:60},  data:{kind:"end",      label:"Journey Complete"} },
      ],
      edges: [
        {id:"e1",source:"s1",target:"m1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e2",source:"m1",target:"b1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e3",source:"b1",sourceHandle:"yes",target:"m2",label:"✅ Confirm",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#059669"},markerEnd:{type:"arrowclosed",color:"#059669"}},
        {id:"e4",source:"b1",sourceHandle:"reschedule",target:"a1",label:"📅 Reschedule",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#d97706"},markerEnd:{type:"arrowclosed",color:"#d97706"}},
        {id:"e5",source:"b1",sourceHandle:"cancel",target:"m3",label:"❌ Cancel",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#dc2626"},markerEnd:{type:"arrowclosed",color:"#dc2626"}},
        {id:"e6",source:"m2",target:"w1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e7",source:"w1",target:"e1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
      ],
    },
    {
      id: "no-show-recovery",
      name: "No-Show Recovery",
      description: "Re-engage patients who missed their appointment with smart retry",
      category: "Recovery",
      icon: "😔",
      color: "#dc2626",
      nodeCount: 7,
      nodes: [
        { id:"s1", type:"start",      position:{x:60,y:200},   data:{kind:"start",      label:"No-Show Detected", content:"no_show"} },
        { id:"m1", type:"message",    position:{x:360,y:200},  data:{kind:"message",    label:"Missed Appointment", content:"Hi {{name}} 👋\n\nWe noticed you missed your *{{treatment}}* appointment today.\n\nNo worries at all! Life happens. 🙏\n\nWould you like to rebook?"} },
        { id:"b1", type:"buttons",    position:{x:720,y:200},  data:{kind:"buttons",    label:"Rebook Options", content:"We'd love to see you, {{name}}!", buttons:[{id:"rebook",label:"📅 Yes, rebook me",text:"📅 Yes, rebook me"},{id:"later",label:"🕐 Contact me later",text:"🕐 Contact me later"},{id:"stop",label:"🚫 Don't contact",text:"🚫 Don't contact"}]} },
        { id:"a1", type:"ai_response",position:{x:1080,y:100}, data:{kind:"ai_response",label:"Rebook Assistant",  aiSystemPrompt:"You are a caring assistant at {{clinic}}. {{name}} wants to rebook their {{treatment}}. Be warm and understanding, apologize for any inconvenience, and ask them to share their preferred date and time. Offer to make the rebooking as easy as possible."} },
        { id:"r1", type:"retry",      position:{x:1080,y:300}, data:{kind:"retry",      label:"Follow-Up Gate",   retryDelayMinutes:2880, maxRetries:2, retryMessage:"Hey {{name}}, just checking in! We still have slots available for your {{treatment}}. Would you like to book? 😊"} },
        { id:"m2", type:"message",    position:{x:1080,y:500}, data:{kind:"message",    label:"Stop Contact",     content:"Of course, {{name}}. We'll respect your privacy and won't contact you again.\n\nIf you ever need us, we're here! 💙\n\n— {{clinic}} Team"} },
        { id:"e1", type:"end",        position:{x:1420,y:200}, data:{kind:"end",        label:"Journey Complete"} },
      ],
      edges: [
        {id:"e1",source:"s1",target:"m1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e2",source:"m1",target:"b1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e3",source:"b1",sourceHandle:"rebook",target:"a1",label:"📅 Rebook",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#059669"},markerEnd:{type:"arrowclosed",color:"#059669"}},
        {id:"e4",source:"b1",sourceHandle:"later",target:"r1",label:"🕐 Later",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#d97706"},markerEnd:{type:"arrowclosed",color:"#d97706"}},
        {id:"e5",source:"b1",sourceHandle:"stop",target:"m2",label:"🚫 Stop",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#dc2626"},markerEnd:{type:"arrowclosed",color:"#dc2626"}},
        {id:"e6",source:"r1",sourceHandle:"responded",target:"a1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#059669"},markerEnd:{type:"arrowclosed",color:"#059669"}},
        {id:"e7",source:"a1",target:"e1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
      ],
    },
    {
      id: "post-treatment",
      name: "Post-Treatment Follow-Up",
      description: "Check on patient after treatment + collect review",
      category: "Feedback",
      icon: "⭐",
      color: "#d97706",
      nodeCount: 9,
      nodes: [
        { id:"s1", type:"start",      position:{x:60,y:200},  data:{kind:"start",      label:"Treatment Done",   content:"completed"} },
        { id:"w1", type:"wait",       position:{x:320,y:200}, data:{kind:"wait",       label:"Wait 2 Hours",     delayMinutes:120} },
        { id:"m1", type:"message",    position:{x:600,y:200}, data:{kind:"message",    label:"How Are You?",     content:"Hi {{name}}! 💙\n\nWe hope you're feeling great after your *{{treatment}}* today!\n\nYour comfort and wellbeing are our top priority."} },
        { id:"b1", type:"buttons",    position:{x:920,y:200}, data:{kind:"buttons",    label:"Feeling Check", content:"How are you feeling, {{name}}?", buttons:[{id:"great",label:"😊 Great!",text:"😊 Great!"},{id:"okay",label:"😐 Okay",text:"😐 Okay"},{id:"pain",label:"😟 Some discomfort",text:"😟 Some discomfort"}]} },
        { id:"sent", type:"sentiment",position:{x:1260,y:200},data:{kind:"sentiment",  label:"Mood Check"} },
        { id:"m2", type:"message",    position:{x:1580,y:60}, data:{kind:"message",    label:"Ask for Review",  content:"That's wonderful to hear! 🎉\n\nWould you mind leaving us a quick review? It helps other patients find us:\n\n⭐ Google Review: [your-google-link]\n\nThank you so much, {{name}}! 🙏"} },
        { id:"a1", type:"ai_response",position:{x:1580,y:260},data:{kind:"ai_response",label:"Care Response",   aiSystemPrompt:"{{name}} is experiencing some discomfort after their {{treatment}} at {{clinic}}. Respond with empathy and care. Provide helpful after-care tips for their treatment type. Offer to schedule a follow-up call. Keep it warm, under 4 sentences."} },
        { id:"m3", type:"message",    position:{x:1580,y:460},data:{kind:"message",    label:"Urgent Care",     content:"{{name}}, we're sorry to hear you're in pain! 😟\n\n*Please contact us immediately:*\n📞 {{clinic}} Emergency: [your-number]\n\nYour health is our priority — we're here for you! 💙"} },
        { id:"e1", type:"end",        position:{x:1900,y:200},data:{kind:"end",        label:"Follow-Up Done"} },
      ],
      edges: [
        {id:"e1",source:"s1",target:"w1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e2",source:"w1",target:"m1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e3",source:"m1",target:"b1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e4",source:"b1",sourceHandle:"great",target:"sent",label:"😊",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#059669"},markerEnd:{type:"arrowclosed",color:"#059669"}},
        {id:"e5",source:"b1",sourceHandle:"okay",target:"sent",label:"😐",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#d97706"},markerEnd:{type:"arrowclosed",color:"#d97706"}},
        {id:"e6",source:"b1",sourceHandle:"pain",target:"m3",label:"😟 Pain",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#dc2626"},markerEnd:{type:"arrowclosed",color:"#dc2626"}},
        {id:"e7",source:"sent",sourceHandle:"positive",target:"m2",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#059669"},markerEnd:{type:"arrowclosed",color:"#059669"}},
        {id:"e8",source:"sent",sourceHandle:"negative",target:"a1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#dc2626"},markerEnd:{type:"arrowclosed",color:"#dc2626"}},
        {id:"e9",source:"m2",target:"e1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
      ],
    },
    {
      id: "new-patient",
      name: "New Patient Onboarding",
      description: "Welcome new patients and collect key info with memory nodes",
      category: "Onboarding",
      icon: "👋",
      color: "#7c3aed",
      nodeCount: 8,
      nodes: [
        { id:"s1", type:"start",    position:{x:60,y:200},  data:{kind:"start",    label:"New Patient",       content:"booking_created"} },
        { id:"m1", type:"message",  position:{x:360,y:200}, data:{kind:"message",  label:"Welcome!",          content:"Welcome to {{clinic}}, {{name}}! 🎉\n\nWe're thrilled to have you as a new patient.\n\nTo make your visit perfect, we'd love to know a little more about you."} },
        { id:"sv1",type:"save_var", position:{x:700,y:200}, data:{kind:"save_var", label:"Save Health Goal",  varName:"health_goal",   varPrompt:"What brings you to us today? What's your main health goal?"} },
        { id:"m2", type:"message",  position:{x:700,y:200}, data:{kind:"message",  label:"Ask Health Goal",   content:"{{name}}, what's your main health goal or concern that brings you to {{clinic}}? 🌟\n\nFeel free to share in your own words!"} },
        { id:"sv2",type:"save_var", position:{x:1060,y:200},data:{kind:"save_var", label:"Save Preferences",  varName:"preferences",   varPrompt:"Any preferences or things we should know?"} },
        { id:"a1", type:"ai_response",position:{x:1060,y:200},data:{kind:"ai_response",label:"Personalised Welcome",aiSystemPrompt:"You are the warmest, most professional receptionist at {{clinic}}. {{name}} has just shared their health goal: {{memory.health_goal}}. Write a personalised, encouraging welcome message that shows you truly care, references their specific goal, and gets them excited about their upcoming {{treatment}} on {{date}}. Max 4 sentences."} },
        { id:"m3", type:"message",  position:{x:1380,y:200},data:{kind:"message",  label:"Pre-Visit Tips",    content:"Before your visit on {{date}}, {{name}}:\n\n✅ Arrive 10 min early\n✅ Bring your ID\n✅ Wear comfortable clothing\n✅ Stay hydrated 💧\n\nAny questions? Just reply here! 💙"} },
        { id:"e1", type:"end",      position:{x:1700,y:200},data:{kind:"end",      label:"Onboarding Done"} },
      ],
      edges: [
        {id:"e1",source:"s1",target:"m1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e2",source:"m1",target:"m2",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e3",source:"m2",target:"sv1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e4",source:"sv1",target:"a1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e5",source:"a1",target:"m3",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
        {id:"e6",source:"m3",target:"e1",type:"deletable",animated:true,style:{strokeWidth:2.5,stroke:"#6366f1"},markerEnd:{type:"arrowclosed",color:"#6366f1"}},
      ],
    },
  ];

  return NextResponse.json(templates);
}
