import type { TemplateDefinition } from '../types/template.types';
import { buildEmailHtml } from './waitlist-email-layout';

export const DEFAULT_LOCALE = 'en';

export const DefaultEmailTemplates: TemplateDefinition[] = [
  {
    id: 'welcome_email',
    name: 'Welcome Email',
    channel: 'email',
    locale: 'en',
    category: 'onboarding',
    subject: 'Welcome to ShieldAI, {{name}}!',
    body: 'Hi {{name}},\n\nWelcome to ShieldAI! Your account has been created successfully.\n\nGet started by completing your profile at {{profile_url}}.\n\nBest regards,\nThe ShieldAI Team',
    htmlBody: '<h1>Welcome to ShieldAI, {{name}}!</h1><p>Your account has been created successfully.</p><p>Get started by <a href="{{profile_url}}">completing your profile</a>.</p><p>Best regards,<br>The ShieldAI Team</p>',
    variables: [
      { name: 'name', type: 'string', required: true },
      { name: 'profile_url', type: 'string', required: true },
    ],
  },
  {
    id: 'welcome_email',
    name: 'Correo de Bienvenida',
    channel: 'email',
    locale: 'es',
    category: 'onboarding',
    subject: '¡Bienvenido a ShieldAI, {{name}}!',
    body: 'Hola {{name}},\n\n¡Bienvenido a ShieldAI! Tu cuenta ha sido creada exitosamente.\n\nComienza completando tu perfil en {{profile_url}}.\n\nSaludos,\nEl equipo de ShieldAI',
    htmlBody: '<h1>¡Bienvenido a ShieldAI, {{name}}!</h1><p>Tu cuenta ha sido creada exitosamente.</p><p>Comienza <a href="{{profile_url}}">completando tu perfil</a>.</p><p>Saludos,<br>El equipo de ShieldAI</p>',
    variables: [
      { name: 'name', type: 'string', required: true },
      { name: 'profile_url', type: 'string', required: true },
    ],
  },
  {
    id: 'alert_notification',
    name: 'Alert Notification',
    channel: 'email',
    locale: 'en',
    category: 'alert',
    subject: 'ShieldAI Alert: {{alert_type}}',
    body: 'Alert: {{alert_type}}\n\nDetails: {{alert_details}}\n\nTime: {{alert_time}}\n\nView details: {{alert_url}}\n\nBest regards,\nThe ShieldAI Team',
    htmlBody: '<h2>ShieldAI Alert: {{alert_type}}</h2><p><strong>Details:</strong> {{alert_details}}</p><p><strong>Time:</strong> {{alert_time}}</p><p><a href="{{alert_url}}">View details</a></p>',
    variables: [
      { name: 'alert_type', type: 'string', required: true },
      { name: 'alert_details', type: 'string', required: true },
      { name: 'alert_time', type: 'string', required: false, defaultValue: 'Just now' },
      { name: 'alert_url', type: 'string', required: false },
    ],
  },
  {
    id: 'alert_notification',
    name: 'Notificación de Alerta',
    channel: 'email',
    locale: 'es',
    category: 'alert',
    subject: 'Alerta de ShieldAI: {{alert_type}}',
    body: 'Alerta: {{alert_type}}\n\nDetalles: {{alert_details}}\n\nHora: {{alert_time}}\n\nVer detalles: {{alert_url}}\n\nSaludos,\nEl equipo de ShieldAI',
    htmlBody: '<h2>Alerta de ShieldAI: {{alert_type}}</h2><p><strong>Detalles:</strong> {{alert_details}}</p><p><strong>Hora:</strong> {{alert_time}}</p><p><a href="{{alert_url}}">Ver detalles</a></p>',
    variables: [
      { name: 'alert_type', type: 'string', required: true },
      { name: 'alert_details', type: 'string', required: true },
      { name: 'alert_time', type: 'string', required: false, defaultValue: 'Ahora mismo' },
      { name: 'alert_url', type: 'string', required: false },
    ],
  },
  {
    id: 'password_reset',
    name: 'Password Reset',
    channel: 'email',
    locale: 'en',
    category: 'account',
    subject: 'Reset Your ShieldAI Password',
    body: 'Hi {{name}},\n\nClick the link below to reset your password:\n\n{{reset_url}}\n\nThe link expires in {{expiry_hours}} hours.\n\nBest regards,\nThe ShieldAI Team',
    htmlBody: '<h2>Reset Your Password</h2><p>Hi {{name}},</p><p>Click the link below to reset your password:</p><p><a href="{{reset_url}}">{{reset_url}}</a></p><p>The link expires in {{expiry_hours}} hours.</p>',
    variables: [
      { name: 'name', type: 'string', required: true },
      { name: 'reset_url', type: 'string', required: true },
      { name: 'expiry_hours', type: 'number', required: false, defaultValue: '24' },
    ],
  },
  {
    id: 'scan_complete',
    name: 'Scan Complete Notification',
    channel: 'email',
    locale: 'en',
    category: 'scan',
    subject: 'Your ShieldAI Scan is Complete',
    body: 'Hi {{name}},\n\nYour {{scan_type}} scan has been completed.\n\nResults: {{scan_result}}\n\nView full report: {{report_url}}\n\nBest regards,\nThe ShieldAI Team',
    htmlBody: '<h2>Scan Complete</h2><p>Hi {{name}}, your {{scan_type}} scan is complete.</p><p><strong>Results:</strong> {{scan_result}}</p><p><a href="{{report_url}}">View full report</a></p>',
    variables: [
      { name: 'name', type: 'string', required: true },
      { name: 'scan_type', type: 'string', required: true },
      { name: 'scan_result', type: 'string', required: true },
      { name: 'report_url', type: 'string', required: true },
    ],
  },
  {
    id: 'report_ready',
    name: 'Report Ready Notification',
    channel: 'email',
    locale: 'en',
    category: 'report',
    subject: 'ShieldAI: {{report_title}} Ready',
    body: 'Hi {{name}},\n\nYour {{report_title}} is ready to view.\n\nSummary: {{report_summary}}\n\nView Report: {{report_url}}\nDownload PDF: {{pdf_url}}\n\nBest regards,\nThe ShieldAI Team',
    htmlBody: `
      <h2>Your ShieldAI Report is Ready</h2>
      <p>Hi {{name}},</p>
      <p><strong>{{report_title}}</strong></p>
      <p>{{report_summary}}</p>
      <p><a href="{{report_url}}">View Report</a></p>
      <p><a href="{{pdf_url}}">Download PDF</a></p>
      <p>Best regards,<br>The ShieldAI Team</p>
    `,
    variables: [
      { name: 'name', type: 'string', required: true },
      { name: 'report_title', type: 'string', required: true },
      { name: 'report_summary', type: 'string', required: false, defaultValue: 'Your protection report contains detailed statistics and recommendations.' },
      { name: 'report_url', type: 'string', required: true },
      { name: 'pdf_url', type: 'string', required: true },
    ],
  },
];

export const DefaultSMSTemplates: TemplateDefinition[] = [
  {
    id: 'alert_sms',
    name: 'Alert SMS',
    channel: 'sms',
    locale: 'en',
    category: 'alert',
    subject: undefined,
    body: 'ShieldAI Alert: {{alert_type}} - {{alert_details}}. View: {{short_url}}',
    variables: [
      { name: 'alert_type', type: 'string', required: true },
      { name: 'alert_details', type: 'string', required: true },
      { name: 'short_url', type: 'string', required: false, defaultValue: 'shieldai.app/alert' },
    ],
  },
  {
    id: 'alert_sms',
    name: 'SMS de Alerta',
    channel: 'sms',
    locale: 'es',
    category: 'alert',
    subject: undefined,
    body: 'Alerta ShieldAI: {{alert_type}} - {{alert_details}}. Ver: {{short_url}}',
    variables: [
      { name: 'alert_type', type: 'string', required: true },
      { name: 'alert_details', type: 'string', required: true },
      { name: 'short_url', type: 'string', required: false, defaultValue: 'shieldai.app/alert' },
    ],
  },
  {
    id: 'verification_sms',
    name: 'Verification Code SMS',
    channel: 'sms',
    locale: 'en',
    category: 'verification',
    subject: undefined,
    body: 'Your ShieldAI verification code is: {{code}}. Expires in {{expiry_minutes}} minutes.',
    variables: [
      { name: 'code', type: 'string', required: true },
      { name: 'expiry_minutes', type: 'number', required: false, defaultValue: '10' },
    ],
  },
];

export const DefaultPushTemplates: TemplateDefinition[] = [
  {
    id: 'alert_push',
    name: 'Alert Push',
    channel: 'push',
    locale: 'en',
    category: 'alert',
    subject: 'ShieldAI Alert: {{alert_type}}',
    body: '{{alert_details}}',
    variables: [
      { name: 'alert_type', type: 'string', required: true },
      { name: 'alert_details', type: 'string', required: true },
    ],
  },
  {
    id: 'alert_push',
    name: 'Notificación de Alerta',
    channel: 'push',
    locale: 'es',
    category: 'alert',
    subject: 'Alerta ShieldAI: {{alert_type}}',
    body: '{{alert_details}}',
    variables: [
      { name: 'alert_type', type: 'string', required: true },
      { name: 'alert_details', type: 'string', required: true },
    ],
  },
];

// ── Waitlist Welcome Sequence ──

function waitlistBody(text: string): string {
  return text.replace(/\n/g, '<br>');
}

export const WaitlistEmailTemplates: TemplateDefinition[] = [
  // Email 1: Immediate Waitlist Confirmation
  {
    id: 'waitlist_confirmation',
    name: 'Waitlist Confirmation',
    channel: 'email',
    locale: 'en',
    category: 'waitlist',
    subject: 'Welcome to the ShieldAI Waitlist!',
    body: `Hi {{name}},

You're on the list!

Welcome to ShieldAI — you're now one step closer to taking control of your digital privacy.

Here's what happens next:
• We'll keep you updated on our progress and launch timeline
• You'll get early access before the general public
• Your spot on the waitlist: #{{position}}

In the meantime, follow us for the latest updates:
• Website: https://shieldai.com
• Blog: https://shieldai.com/blog

Stay safe,
The ShieldAI Team`,
    htmlBody: buildEmailHtml({
      previewText: "You're on the list! Welcome to ShieldAI.",
      title: "You're on the List! 🛡️",
      bodyContent: waitlistBody(`Hi {{name}},

Thanks for joining the ShieldAI waitlist. You're now one step closer to taking control of your digital privacy.

<strong>Your spot on the waitlist: #{{position}}</strong>

Here's what to expect:
• Priority early access before the general public
• Launch day updates straight to your inbox
• Exclusive insights on digital privacy and protection

While you wait, explore our blog for tips on protecting your identity online.`),
      ctaText: 'Visit ShieldAI Blog',
      ctaUrl: 'https://shieldai.com/blog',
      footerNote: 'This confirmation confirms your spot on the ShieldAI waitlist. You received this because you signed up at shieldai.com.',
    }),
    variables: [
      { name: 'name', type: 'string', required: false, defaultValue: 'there' },
      { name: 'position', type: 'string', required: true },
      { name: 'unsubscribe_url', type: 'string', required: false, defaultValue: 'https://shieldai.com/unsubscribe' },
    ],
  },
  {
    id: 'waitlist_confirmation',
    name: 'Confirmación de Lista de Espera',
    channel: 'email',
    locale: 'es',
    category: 'waitlist',
    subject: '¡Bienvenido a la Lista de Espera de ShieldAI!',
    body: `Hola {{name}},

¡Estás en la lista!

Bienvenido a ShieldAI — estás un paso más cerca de tomar el control de tu privacidad digital.

Esto es lo que sigue:
• Te mantendremos al tanto de nuestro progreso y fechas de lanzamiento
• Tendrás acceso anticipado antes que el público general
• Tu lugar en la lista: #{{position}}

Mantente seguro,
El equipo de ShieldAI`,
    htmlBody: buildEmailHtml({
      previewText: '¡Estás en la lista! Bienvenido a ShieldAI.',
      title: '¡Estás en la Lista! 🛡️',
      bodyContent: waitlistBody(`Hola {{name}},

Gracias por unirte a la lista de espera de ShieldAI. Estás un paso más cerca de tomar el control de tu privacidad digital.

<strong>Tu lugar en la lista: #{{position}}</strong>

Esto es lo que puedes esperar:
• Acceso prioritario anticipado antes que el público general
• Actualizaciones del lanzamiento directamente en tu bandeja de entrada
• Consejos exclusivos sobre privacidad y protección digital`),
      ctaText: 'Visitar el Blog de ShieldAI',
      ctaUrl: 'https://shieldai.com/blog',
      footerNote: 'Esta confirmación asegura tu lugar en la lista de espera de ShieldAI. Recibiste esto porque te registraste en shieldai.com.',
    }),
    variables: [
      { name: 'name', type: 'string', required: false, defaultValue: 'there' },
      { name: 'position', type: 'string', required: true },
      { name: 'unsubscribe_url', type: 'string', required: false, defaultValue: 'https://shieldai.com/unsubscribe' },
    ],
  },

  // Email 2: Day 1 — Intro to ShieldAI
  {
    id: 'waitlist_intro',
    name: 'Welcome to ShieldAI — Intro',
    channel: 'email',
    locale: 'en',
    category: 'waitlist',
    subject: 'ShieldAI: Your Privacy Protection Starts Here',
    body: `Hi {{name}},

Every day, scammers use AI-powered tools to clone voices, craft convincing phishing messages, and steal identities. ShieldAI is built to stop them.

We monitor what matters most:
• Dark web scans for your phone number, email, and passwords
• AI-powered spam call and text filtering
• Voice cloning detection to protect your family
• Identity theft monitoring and alerts

And coming soon — home title protection.

You're on the ground floor of something important. As a waitlist member, you'll get early access, exclusive updates, and a special launch offer.

Stay safe,
The ShieldAI Team`,
    htmlBody: buildEmailHtml({
      previewText: 'Discover how ShieldAI protects you from AI-powered scams.',
      title: 'Your Privacy Protection Starts Here',
      bodyContent: waitlistBody(`Hi {{name}},

Every day, scammers use AI-powered tools to clone voices, craft convincing phishing messages, and steal identities. ShieldAI is built to stop them.

<strong>What we monitor:</strong>
• Dark web scans for your phone number, email, and passwords
• AI-powered spam call and text filtering
• Voice cloning detection to protect your family
• Identity theft monitoring and real-time alerts

And coming soon — home title protection.

As a waitlist member, you'll get early access, exclusive updates, and a special launch offer.`),
      ctaText: 'Learn More About ShieldAI',
      ctaUrl: 'https://shieldai.com',
      footerNote: 'Email 2 of 4 in your welcome sequence. You received this because you joined the ShieldAI waitlist.',
    }),
    variables: [
      { name: 'name', type: 'string', required: false, defaultValue: 'there' },
      { name: 'unsubscribe_url', type: 'string', required: false, defaultValue: 'https://shieldai.com/unsubscribe' },
    ],
  },

  // Email 3: Day 3 — Features Deep Dive
  {
    id: 'waitlist_features',
    name: 'ShieldAI Features Overview',
    channel: 'email',
    locale: 'en',
    category: 'waitlist',
    subject: 'See What ShieldAI Can Do For You',
    body: `Hi {{name}},

Let's dive into what ShieldAI actually does. Here's a closer look at each layer of protection:

🔍 DarkWatch — Dark Web Monitoring
We continuously scan dark web forums, data breaches, and credential dumps for your personal information. If your email, phone, or passwords appear somewhere they shouldn't, you'll know instantly.

📞 SpamShield — Call & Text Protection
AI-powered filtering that blocks spam calls, detects phishing texts, and flags suspicious numbers before they reach you. Works across your phone lines.

🎙️ VoicePrint — Voice Clone Detection
One of the most alarming new scams: AI voice cloning. VoicePrint analyzes incoming calls for synthetic voice patterns and alerts you if someone is impersonating a loved one.

🏠 Coming Soon: Home Title Monitoring
We're building protection against property fraud — alerting you to any changes in your home's title or deed.

Want to dive deeper? Check out our blog for detailed guides on each feature.`,
    htmlBody: buildEmailHtml({
      previewText: 'A closer look at DarkWatch, SpamShield, VoicePrint, and more.',
      title: 'See What ShieldAI Can Do For You',
      bodyContent: waitlistBody(`Hi {{name}},

Let's dive into what ShieldAI actually does:

<strong>🔍 DarkWatch — Dark Web Monitoring</strong>
We continuously scan dark web forums, data breaches, and credential dumps for your personal information. If your email, phone, or passwords appear somewhere they shouldn't, you'll know instantly.

<strong>📞 SpamShield — Call & Text Protection</strong>
AI-powered filtering that blocks spam calls, detects phishing texts, and flags suspicious numbers before they reach you.

<strong>🎙️ VoicePrint — Voice Clone Detection</strong>
One of the most alarming new scams: AI voice cloning. VoicePrint analyzes calls for synthetic voice patterns and alerts you if someone is impersonating a loved one.

<strong>🏠 Coming Soon: Home Title Monitoring</strong>
Protection against property fraud — alerting you to changes in your home's title or deed.`),
      ctaText: 'Read Our Privacy Guides',
      ctaUrl: 'https://shieldai.com/blog',
      footerNote: 'Email 3 of 4 in your welcome sequence. You received this because you joined the ShieldAI waitlist.',
    }),
    variables: [
      { name: 'name', type: 'string', required: false, defaultValue: 'there' },
      { name: 'unsubscribe_url', type: 'string', required: false, defaultValue: 'https://shieldai.com/unsubscribe' },
    ],
  },

  // Email 4: Day 7 — Launch Teaser
  {
    id: 'waitlist_launch_teaser',
    name: 'ShieldAI Launch Teaser',
    channel: 'email',
    locale: 'en',
    category: 'waitlist',
    subject: 'Something Big Is Coming — Get Ready',
    body: `Hi {{name}},

Big news — we're getting ready to launch.

As an early waitlist member, here's what you need to know:

🚀 Launch Timeline
We're putting the final touches on ShieldAI and preparing for our public launch. You'll be among the first to get access.

🎁 Your Early Adopter Perks
• Priority access before the general public
• Exclusive launch pricing for waitlist members
• Free DarkWatch scan setup when you join

📣 Spread the Word
Know someone who could use better privacy protection? Share your waitlist link and move up the list:

{{referral_url}}

We'll be in touch soon with more details. Get ready to take control of your digital life.

Stay safe,
The ShieldAI Team`,
    htmlBody: buildEmailHtml({
      previewText: 'Launch is near. Here\'s what waitlist members need to know.',
      title: 'Something Big Is Coming',
      bodyContent: waitlistBody(`Hi {{name}},

Big news — we're getting ready to launch.

<strong>🚀 Launch Timeline</strong>
We're putting the final touches on ShieldAI. You'll be among the first to get access.

<strong>🎁 Your Early Adopter Perks</strong>
• Priority access before the general public
• Exclusive launch pricing for waitlist members
• Free DarkWatch scan setup when you join

<strong>📣 Spread the Word</strong>
Know someone who could use better privacy protection? Share your referral link:

{{referral_url}}`),
      ctaText: 'Share ShieldAI',
      ctaUrl: 'https://shieldai.com',
      footerNote: 'Email 4 of 4 in your welcome sequence. This is our last pre-launch update — stay tuned for launch day!',
    }),
    variables: [
      { name: 'name', type: 'string', required: false, defaultValue: 'there' },
      { name: 'referral_url', type: 'string', required: false, defaultValue: 'https://shieldai.com/waitlist' },
      { name: 'unsubscribe_url', type: 'string', required: false, defaultValue: 'https://shieldai.com/unsubscribe' },
    ],
  },
];

export const AllDefaultTemplates: TemplateDefinition[] = [
  ...DefaultEmailTemplates,
  ...WaitlistEmailTemplates,
  ...DefaultSMSTemplates,
  ...DefaultPushTemplates,
];
