import type { NewEmailTemplate } from "@/lib/db/schema";

/**
 * Source-of-truth defaults for every transactional email the site sends.
 * Copy is rendered through a tiny mustache-style replacer — supported
 * variables are listed per template.
 */
export const EMAIL_TEMPLATE_DEFAULTS: NewEmailTemplate[] = [
  {
    slug: "admin-new-application",
    name: "Admin — new application",
    description:
      "Sent to approvers when a new membership application is submitted.",
    subject: "[OrthoGlobe] New membership application — {{applicantName}}",
    variables: [
      "applicantName",
      "applicantEmail",
      "institution",
      "country",
      "motivation",
      "reviewUrl",
    ],
    body: `New membership application:

Name:        {{applicantName}}
Email:       {{applicantEmail}}
Institution: {{institution}}
Country:     {{country}}

Motivation:
{{motivation}}

Review:
{{reviewUrl}}

This link expires in 7 days.
`,
  },
  {
    slug: "applicant-approved",
    name: "Applicant — approved",
    description: "Sent to a new member when their application is approved.",
    subject: "[OrthoGlobe] Your membership has been approved",
    variables: ["name", "loginUrl"],
    body: `Hi {{name}},

Welcome to OrthoGlobe. Your membership application has been approved.

Sign in here:
{{loginUrl}}

— The OrthoGlobe team
`,
  },
  {
    slug: "applicant-rejected",
    name: "Applicant — rejected",
    description:
      "Sent to an applicant when their application is declined. {{notes}} is optional.",
    subject: "[OrthoGlobe] Update on your membership application",
    variables: ["name", "notes"],
    body: `Hi {{name}},

Thank you for applying to OrthoGlobe. After review we are unable to approve your application at this time.

{{notesBlock}}You are welcome to reapply in the future.

— The OrthoGlobe team
`,
  },
  {
    slug: "password-reset",
    name: "Password reset",
    description:
      "Sent when a member requests a password reset. Token expires in 1 hour.",
    subject: "[OrthoGlobe] Reset your password",
    variables: ["name", "resetUrl", "expiresInMinutes"],
    body: `Hi {{name}},

Someone — hopefully you — asked to reset the password on your OrthoGlobe account.

Use this link within the next {{expiresInMinutes}} minutes:
{{resetUrl}}

If you didn't request this, you can safely ignore this email. Your current password will continue to work.

— The OrthoGlobe team
`,
  },
  {
    slug: "password-reset-admin",
    name: "Admin-initiated password reset",
    description:
      "Sent when an admin resets a member's password on their behalf.",
    subject: "[OrthoGlobe] Set a new password for your account",
    variables: ["name", "resetUrl", "adminName", "expiresInMinutes"],
    body: `Hi {{name}},

An OrthoGlobe administrator ({{adminName}}) has issued a password reset for your account.

Set a new password within the next {{expiresInMinutes}} minutes:
{{resetUrl}}

If you weren't expecting this, please contact us.

— The OrthoGlobe team
`,
  },
  {
    slug: "password-changed",
    name: "Password changed confirmation",
    description: "Sent after a password change succeeds.",
    subject: "[OrthoGlobe] Your password was changed",
    variables: ["name", "changedAt"],
    body: `Hi {{name}},

This is a confirmation that the password on your OrthoGlobe account was changed on {{changedAt}}.

If this wasn't you, contact us immediately — someone may have access to your account.

— The OrthoGlobe team
`,
  },
  {
    slug: "research-application-received",
    name: "Research — application received (applicant)",
    description:
      "Sent to a member after they submit an application to collaborate on a study.",
    subject: "[OrthoGlobe Research] We received your application — {{studyTitle}}",
    variables: ["name", "studyTitle", "rolePreference"],
    body: `Hi {{name}},

Thanks for applying to collaborate on "{{studyTitle}}". We've logged your interest for the {{rolePreference}} role.

A study coordinator will review your application and be in touch within 14 days. You don't need to do anything in the meantime.

— The OrthoGlobe Research team
`,
  },
  {
    slug: "research-application-admin-notify",
    name: "Research — application received (admins)",
    description:
      "Sent to admin approvers when a new study application arrives.",
    subject:
      "[OrthoGlobe Research] New application — {{studyTitle}} — {{name}}",
    variables: [
      "name",
      "email",
      "institution",
      "country",
      "studyTitle",
      "rolePreference",
      "motivation",
      "reviewUrl",
    ],
    body: `New study application:

Study:       {{studyTitle}}
Applicant:   {{name}}
Email:       {{email}}
Institution: {{institution}}
Country:     {{country}}
Role:        {{rolePreference}}

Motivation:
{{motivation}}

Review:
{{reviewUrl}}
`,
  },
  {
    slug: "research-proposal-received",
    name: "Research — proposal received (proposer)",
    description:
      "Sent to a proposer after they submit a new study proposal through the portal.",
    subject: "[OrthoGlobe Research] We received your study proposal",
    variables: ["name", "title"],
    body: `Hi {{name}},

Thanks for proposing "{{title}}" to OrthoGlobe. Your submission is with the steering committee; we aim to respond within 30 days.

If the committee wants to discuss the idea further we'll reach out to schedule a call.

— The OrthoGlobe Research team
`,
  },
  {
    slug: "research-proposal-admin-notify",
    name: "Research — proposal received (admins)",
    description: "Sent to admin approvers when a new study proposal arrives.",
    subject: "[OrthoGlobe Research] New study proposal — {{title}}",
    variables: [
      "name",
      "email",
      "institution",
      "country",
      "title",
      "specialty",
      "hypothesis",
      "reviewUrl",
    ],
    body: `New study proposal:

Title:       {{title}}
Proposer:    {{name}}
Email:       {{email}}
Institution: {{institution}}
Country:     {{country}}
Specialty:   {{specialty}}

Hypothesis:
{{hypothesis}}

Review:
{{reviewUrl}}
`,
  },
  {
    slug: "store-order-received",
    name: "Store — order received (customer)",
    description:
      "Sent to a customer immediately after placing an order. We collect payment by invoice rather than card at checkout.",
    subject: "[OrthoGlobe Store] Order {{orderNumber}} received",
    variables: [
      "name",
      "orderNumber",
      "itemsBlock",
      "subtotal",
      "shipping",
      "total",
      "orderUrl",
    ],
    body: `Hi {{name}},

Thanks for your order. We've received:

{{itemsBlock}}

Subtotal: {{subtotal}}
Shipping: {{shipping}}
Total:    {{total}}

An OrthoGlobe team member will issue an invoice within two working days. You can track your order here:
{{orderUrl}}

— OrthoGlobe Store
`,
  },
  {
    slug: "store-order-admin-notify",
    name: "Store — order received (admins)",
    description: "Sent to admins when a new store order is placed.",
    subject: "[OrthoGlobe Store] New order {{orderNumber}} — {{name}}",
    variables: [
      "name",
      "email",
      "orderNumber",
      "shippingAddress",
      "itemsBlock",
      "total",
      "reviewUrl",
    ],
    body: `New store order:

Number:   {{orderNumber}}
Customer: {{name}} <{{email}}>

Items:
{{itemsBlock}}

Total:    {{total}}

Ship to:
{{shippingAddress}}

Review + invoice:
{{reviewUrl}}
`,
  },
  {
    slug: "store-order-status-changed",
    name: "Store — order status update",
    description:
      "Sent when an admin moves an order to invoiced, paid, shipped, delivered, or cancelled.",
    subject:
      "[OrthoGlobe Store] Order {{orderNumber}} — {{statusLabel}}",
    variables: [
      "name",
      "orderNumber",
      "statusLabel",
      "statusBlock",
      "orderUrl",
    ],
    body: `Hi {{name}},

An update on your OrthoGlobe Store order {{orderNumber}}:

{{statusBlock}}

Track your order here:
{{orderUrl}}

— OrthoGlobe Store
`,
  },
  {
    slug: "research-application-decision",
    name: "Research — application decision",
    description:
      "Sent to an applicant when a study admin accepts or declines their application.",
    subject:
      "[OrthoGlobe Research] Update on your application — {{studyTitle}}",
    variables: ["name", "studyTitle", "decision", "decisionBlock", "reviewNotes"],
    body: `Hi {{name}},

Update on your application to collaborate on "{{studyTitle}}":

{{decisionBlock}}

{{reviewNotes}}

— The OrthoGlobe Research team
`,
  },
];
