import type { Email } from '@/lib/jmap/types';
import { demoDate } from '../demo-utils';

export function createDemoEmails(): Email[] {
  return [
    // ── Inbox ───────────────────────────────────────────────────
    {
      id: 'demo-email-1',
      threadId: 'demo-thread-1',
      mailboxIds: { 'demo-mailbox-inbox': true },
      keywords: {},
      size: 4200,
      receivedAt: demoDate(0, -2),
      from: [{ name: 'Bulwark Team', email: 'welcome@bulwark.email' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Welcome to Bulwark Mail!',
      sentAt: demoDate(0, -2),
      preview: 'Thanks for trying out Bulwark Mail. This is a demo environment where you can explore all features...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-1', size: 350, type: 'text/plain' }],
      htmlBody: [{ partId: '2', blobId: 'blob-2', size: 800, type: 'text/html' }],
      bodyValues: {
        '1': { value: 'Thanks for trying out Bulwark Mail!\n\nThis is a demo environment where you can explore all features without connecting to a real server. All data stays on your device.\n\nFeel free to:\n- Read, compose, and organize emails\n- Manage contacts and calendars\n- Configure filters and settings\n- Try keyboard shortcuts (press ? to see them)\n\nEnjoy exploring!' },
        '2': { value: '<div><h2>Welcome to Bulwark Mail!</h2><p>Thanks for trying out Bulwark Mail!</p><p>This is a demo environment where you can explore all features without connecting to a real server. <strong>All data stays on your device.</strong></p><p>Feel free to:</p><ul><li>Read, compose, and organize emails</li><li>Manage contacts and calendars</li><li>Configure filters and settings</li><li>Try keyboard shortcuts (press <kbd>?</kbd> to see them)</li></ul><p>Enjoy exploring!</p></div>' },
      },
      messageId: '<welcome@demo.bulwark.email>',
    },
    {
      id: 'demo-email-2',
      threadId: 'demo-thread-2',
      mailboxIds: { 'demo-mailbox-inbox': true },
      keywords: { $seen: true },
      size: 18500,
      receivedAt: demoDate(-1, -5),
      from: [{ name: 'TechDigest Weekly', email: 'newsletter@techdigest.example' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: 'This Week in Tech: AI Developments & Open Source Updates',
      sentAt: demoDate(-1, -5),
      preview: 'Your weekly roundup of the most important technology news and open source developments...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-3', size: 2400, type: 'text/plain' }],
      htmlBody: [{ partId: '2', blobId: 'blob-4', size: 5200, type: 'text/html' }],
      bodyValues: {
        '1': { value: 'This Week in Tech\n\n1. AI-Powered Code Review Tools\nNew tools are making code reviews faster and more thorough...\n\n2. Open Source Licensing Update\nThe OSI has published new guidelines for AI-generated code...\n\n3. WebAssembly 2.0 Draft\nThe W3C has released the first draft of WebAssembly 2.0...\n\nRead more at techdigest.example' },
        '2': { value: '<div style="max-width:600px;margin:0 auto;"><h1>This Week in Tech</h1><h3>1. AI-Powered Code Review Tools</h3><p>New tools are making code reviews faster and more thorough, with several open-source options gaining traction.</p><h3>2. Open Source Licensing Update</h3><p>The OSI has published new guidelines for AI-generated code contributions to open source projects.</p><h3>3. WebAssembly 2.0 Draft</h3><p>The W3C has released the first draft of WebAssembly 2.0, promising improved memory management.</p></div>' },
      },
      messageId: '<weekly-42@techdigest.example>',
    },
    // Thread: Project discussion (3 emails in same thread)
    {
      id: 'demo-email-3a',
      threadId: 'demo-thread-3',
      mailboxIds: { 'demo-mailbox-inbox': true },
      keywords: { $seen: true },
      size: 3100,
      receivedAt: demoDate(-3, -10),
      from: [{ name: 'Alice Johnson', email: 'alice.johnson@example.com' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }, { name: 'Bob Chen', email: 'bob.chen@example.com' }],
      subject: 'Q4 Project Timeline',
      sentAt: demoDate(-3, -10),
      preview: 'Hi team, I wanted to share the updated timeline for our Q4 deliverables...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-5', size: 450, type: 'text/plain' }],
      htmlBody: [{ partId: '2', blobId: 'blob-6', size: 650, type: 'text/html' }],
      bodyValues: {
        '1': { value: 'Hi team,\n\nI wanted to share the updated timeline for our Q4 deliverables:\n\n- Phase 1: Design review - Oct 15\n- Phase 2: Development - Nov 1-30\n- Phase 3: Testing - Dec 1-15\n- Phase 4: Launch - Dec 20\n\nPlease review and let me know if you see any conflicts.\n\nBest,\nAlice' },
        '2': { value: '<p>Hi team,</p><p>I wanted to share the updated timeline for our Q4 deliverables:</p><ul><li>Phase 1: Design review - Oct 15</li><li>Phase 2: Development - Nov 1-30</li><li>Phase 3: Testing - Dec 1-15</li><li>Phase 4: Launch - Dec 20</li></ul><p>Please review and let me know if you see any conflicts.</p><p>Best,<br>Alice</p>' },
      },
      messageId: '<q4-timeline-1@example.com>',
    },
    {
      id: 'demo-email-3b',
      threadId: 'demo-thread-3',
      mailboxIds: { 'demo-mailbox-inbox': true },
      keywords: { $seen: true },
      size: 3500,
      receivedAt: demoDate(-2, -8),
      from: [{ name: 'Bob Chen', email: 'bob.chen@example.com' }],
      to: [{ name: 'Alice Johnson', email: 'alice.johnson@example.com' }, { name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Re: Q4 Project Timeline',
      sentAt: demoDate(-2, -8),
      preview: 'Looks good to me! One concern: the testing window might be tight given the holidays...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-7', size: 520, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Looks good to me! One concern: the testing window might be tight given the holidays. Could we start testing a few days earlier?\n\nAlso, should we set up a shared doc for tracking blockers?\n\n- Bob' },
      },
      messageId: '<q4-timeline-2@example.com>',
      inReplyTo: ['<q4-timeline-1@example.com>'],
      references: ['<q4-timeline-1@example.com>'],
    },
    {
      id: 'demo-email-3c',
      threadId: 'demo-thread-3',
      mailboxIds: { 'demo-mailbox-inbox': true },
      keywords: {},
      size: 3800,
      receivedAt: demoDate(-1, -3),
      from: [{ name: 'Alice Johnson', email: 'alice.johnson@example.com' }],
      to: [{ name: 'Bob Chen', email: 'bob.chen@example.com' }, { name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Re: Q4 Project Timeline',
      sentAt: demoDate(-1, -3),
      preview: 'Great point Bob. Let\'s move testing to Nov 28. I\'ll create the shared doc today...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-8', size: 400, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Great point Bob. Let\'s move testing to Nov 28. I\'ll create the shared doc today and share the link.\n\nUpdated timeline:\n- Design review: Oct 15\n- Development: Nov 1-27\n- Testing: Nov 28 - Dec 15\n- Launch: Dec 20\n\n- Alice' },
      },
      messageId: '<q4-timeline-3@example.com>',
      inReplyTo: ['<q4-timeline-2@example.com>'],
      references: ['<q4-timeline-1@example.com>', '<q4-timeline-2@example.com>'],
    },
    // Email with attachments
    {
      id: 'demo-email-4',
      threadId: 'demo-thread-4',
      mailboxIds: { 'demo-mailbox-inbox': true },
      keywords: {},
      size: 245000,
      receivedAt: demoDate(0, -6),
      from: [{ name: 'Sarah Kim', email: 'sarah.kim@example.com' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Invoice #2024-089 & Project Screenshot',
      sentAt: demoDate(0, -6),
      preview: 'Hi, please find attached the invoice for October and a screenshot of the latest prototype...',
      hasAttachment: true,
      textBody: [{ partId: '1', blobId: 'blob-9', size: 280, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Hi,\n\nPlease find attached the invoice for October and a screenshot of the latest prototype.\n\nLet me know if you have any questions.\n\nBest regards,\nSarah' },
      },
      attachments: [
        { partId: 'att-1', blobId: 'demo-blob-att-1', size: 145000, name: 'Invoice-2024-089.pdf', type: 'application/pdf' },
        { partId: 'att-2', blobId: 'demo-blob-att-2', size: 89000, name: 'prototype-v3.png', type: 'image/png' },
      ],
      messageId: '<invoice-089@example.com>',
    },
    // Starred email
    {
      id: 'demo-email-5',
      threadId: 'demo-thread-5',
      mailboxIds: { 'demo-mailbox-inbox': true },
      keywords: { $seen: true, $flagged: true },
      size: 2800,
      receivedAt: demoDate(-2, -1),
      from: [{ name: 'Carlos Rivera', email: 'carlos.rivera@example.com' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Reminder: Team Dinner Friday',
      sentAt: demoDate(-2, -1),
      preview: 'Hey! Just a reminder about our team dinner this Friday at 7 PM at The Garden Bistro...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-10', size: 320, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Hey!\n\nJust a reminder about our team dinner this Friday at 7 PM at The Garden Bistro. I\'ve made a reservation for 8 people.\n\nAddress: 123 Oak Street\n\nLet me know if you can make it!\n\nCheers,\nCarlos' },
      },
      messageId: '<dinner-reminder@example.com>',
    },

    // ── Sent ────────────────────────────────────────────────────
    {
      id: 'demo-email-6',
      threadId: 'demo-thread-6',
      mailboxIds: { 'demo-mailbox-sent': true },
      keywords: { $seen: true },
      size: 2100,
      receivedAt: demoDate(-1, -4),
      from: [{ name: 'Demo User', email: 'demo@example.com' }],
      to: [{ name: 'Alice Johnson', email: 'alice.johnson@example.com' }],
      subject: 'Updated Requirements Document',
      sentAt: demoDate(-1, -4),
      preview: 'Hi Alice, I\'ve updated the requirements document with the changes we discussed...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-11', size: 290, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Hi Alice,\n\nI\'ve updated the requirements document with the changes we discussed in yesterday\'s meeting. The main updates are in sections 3 and 5.\n\nLet me know if you have any questions.\n\nBest,\nDemo User' },
      },
      messageId: '<sent-1@example.com>',
    },
    {
      id: 'demo-email-7',
      threadId: 'demo-thread-7',
      mailboxIds: { 'demo-mailbox-sent': true },
      keywords: { $seen: true },
      size: 1800,
      receivedAt: demoDate(-4, -2),
      from: [{ name: 'Demo User', email: 'demo@example.com' }],
      to: [{ name: 'Sarah Kim', email: 'sarah.kim@example.com' }],
      subject: 'Re: Design Feedback',
      sentAt: demoDate(-4, -2),
      preview: 'Thanks Sarah! The new color scheme looks great. I especially like the contrast improvements...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-12', size: 250, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Thanks Sarah! The new color scheme looks great. I especially like the contrast improvements for accessibility.\n\nLet\'s go with Option B for the navigation.\n\nBest,\nDemo User' },
      },
      messageId: '<sent-2@example.com>',
    },

    // ── Drafts ──────────────────────────────────────────────────
    {
      id: 'demo-email-8',
      threadId: 'demo-thread-8',
      mailboxIds: { 'demo-mailbox-drafts': true },
      keywords: { $seen: true, $draft: true },
      size: 900,
      receivedAt: demoDate(0, -1),
      from: [{ name: 'Demo User', email: 'demo@example.com' }],
      to: [{ name: 'Bob Chen', email: 'bob.chen@example.com' }],
      subject: 'Meeting Notes - Draft',
      sentAt: demoDate(0, -1),
      preview: 'Here are the notes from today\'s standup...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-13', size: 180, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Here are the notes from today\'s standup:\n\n- API integration on track\n- Need to resolve the caching issue\n- ' },
      },
      messageId: '<draft-1@example.com>',
    },

    // ── Trash ───────────────────────────────────────────────────
    {
      id: 'demo-email-9',
      threadId: 'demo-thread-9',
      mailboxIds: { 'demo-mailbox-trash': true },
      keywords: { $seen: true },
      size: 15200,
      receivedAt: demoDate(-5, -3),
      from: [{ name: 'Promo Store', email: 'deals@promostore.example' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: '🎉 Flash Sale: 50% Off Everything!',
      sentAt: demoDate(-5, -3),
      preview: 'Limited time offer! Get 50% off all items in our store...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-14', size: 400, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Limited time offer! Get 50% off all items in our store. Use code FLASH50 at checkout.' },
      },
      messageId: '<promo-1@promostore.example>',
    },
    {
      id: 'demo-email-10',
      threadId: 'demo-thread-10',
      mailboxIds: { 'demo-mailbox-trash': true },
      keywords: { $seen: true },
      size: 2300,
      receivedAt: demoDate(-7, 0),
      from: [{ name: 'System Notification', email: 'noreply@service.example' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Your password was changed',
      sentAt: demoDate(-7, 0),
      preview: 'Your account password was successfully changed on...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-15', size: 200, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Your account password was successfully changed. If you did not make this change, please contact support immediately.' },
      },
      messageId: '<notification-1@service.example>',
    },

    // ── Projects ────────────────────────────────────────────────
    {
      id: 'demo-email-11',
      threadId: 'demo-thread-11',
      mailboxIds: { 'demo-mailbox-projects': true },
      keywords: { $seen: true, $flagged: true },
      size: 4500,
      receivedAt: demoDate(-2, -7),
      from: [{ name: 'Alice Johnson', email: 'alice.johnson@example.com' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: '[Project] Sprint Planning Agenda',
      sentAt: demoDate(-2, -7),
      preview: 'Here\'s the agenda for next week\'s sprint planning session...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-16', size: 600, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Hi team,\n\nHere\'s the agenda for next week\'s sprint planning:\n\n1. Review previous sprint velocity\n2. Discuss tech debt items\n3. Prioritize backlog\n4. Assign story points\n5. Capacity planning\n\nPlease come prepared with your updates.\n\nThanks,\nAlice' },
      },
      messageId: '<project-1@example.com>',
    },
    {
      id: 'demo-email-12',
      threadId: 'demo-thread-12',
      mailboxIds: { 'demo-mailbox-projects': true },
      keywords: {},
      size: 3200,
      receivedAt: demoDate(0, -8),
      from: [{ name: 'Bob Chen', email: 'bob.chen@example.com' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: '[Project] API Rate Limiting Discussion',
      sentAt: demoDate(0, -8),
      preview: 'I\'ve been thinking about our rate limiting approach and wanted to propose a few changes...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-17', size: 480, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Hey,\n\nI\'ve been thinking about our rate limiting approach and wanted to propose:\n\n1. Token bucket algorithm instead of fixed window\n2. Per-endpoint limits rather than global\n3. Graduated response (warn → throttle → block)\n\nThoughts? I can put together a more detailed RFC if we agree on the direction.\n\n- Bob' },
      },
      messageId: '<project-2@example.com>',
    },

    // ── Archive ─────────────────────────────────────────────────
    {
      id: 'demo-email-13',
      threadId: 'demo-thread-13',
      mailboxIds: { 'demo-mailbox-archive': true },
      keywords: { $seen: true },
      size: 2600,
      receivedAt: demoDate(-14, -6),
      from: [{ name: 'HR Department', email: 'hr@company.example' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Updated PTO Policy - Effective January 1',
      sentAt: demoDate(-14, -6),
      preview: 'Please review the updated PTO policy that takes effect January 1st...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-18', size: 380, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Dear team,\n\nPlease review the updated PTO policy effective January 1st. Key changes include:\n\n- Increased annual allowance from 20 to 25 days\n- Flexible half-day options\n- Rollover limit increased to 10 days\n\nPlease acknowledge receipt.\n\nBest,\nHR Department' },
      },
      messageId: '<hr-policy-1@company.example>',
    },

    // ── Receipts ────────────────────────────────────────────────
    {
      id: 'demo-email-14',
      threadId: 'demo-thread-14',
      mailboxIds: { 'demo-mailbox-receipts': true },
      keywords: { $seen: true },
      size: 5200,
      receivedAt: demoDate(-3, -12),
      from: [{ name: 'Cloud Services', email: 'billing@cloudprovider.example' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Payment Receipt - Invoice #INV-2024-1042',
      sentAt: demoDate(-3, -12),
      preview: 'Your payment of $49.99 has been processed successfully...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-19', size: 350, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Payment Confirmation\n\nAmount: $49.99\nDate: Processing date\nInvoice: INV-2024-1042\nService: Cloud Hosting (Standard Plan)\n\nThank you for your payment.' },
      },
      messageId: '<receipt-1@cloudprovider.example>',
    },

    // ── Spam ────────────────────────────────────────────────────
    {
      id: 'demo-email-15',
      threadId: 'demo-thread-15',
      mailboxIds: { 'demo-mailbox-junk': true },
      keywords: {},
      size: 8900,
      receivedAt: demoDate(-1, -9),
      from: [{ name: 'Prize Center', email: 'winner@totallylegit.example' }],
      to: [{ name: 'Demo User', email: 'demo@example.com' }],
      subject: 'Congratulations! You Won $1,000,000!!!',
      sentAt: demoDate(-1, -9),
      preview: 'Dear lucky winner, you have been selected to receive one million dollars...',
      hasAttachment: false,
      textBody: [{ partId: '1', blobId: 'blob-20', size: 500, type: 'text/plain' }],
      bodyValues: {
        '1': { value: 'Dear lucky winner,\n\nYou have been selected to receive ONE MILLION DOLLARS! Click below to claim your prize immediately.\n\n[This is a demo spam email]' },
      },
      messageId: '<spam-1@totallylegit.example>',
    },
  ];
}
