#!/usr/bin/env python3
"""
Seed default email templates.

Run: python scripts/seed_email_templates.py
"""

import json
import sys
from pathlib import Path

# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent))

from app.core.database import get_db
from app.modules.messaging.models import EmailCategory, EmailTemplate


# =============================================================================
# EMAIL TEMPLATES
# =============================================================================

TEMPLATES = [
    # -------------------------------------------------------------------------
    # SIGNUP WELCOME
    # -------------------------------------------------------------------------
    {
        "code": "signup_welcome",
        "language": "en",
        "name": "Signup Welcome",
        "description": "Sent to new vendors after successful signup",
        "category": EmailCategory.AUTH.value,
        "variables": json.dumps([
            "first_name", "company_name", "email", "vendor_code",
            "login_url", "trial_days", "tier_name"
        ]),
        "subject": "Welcome to Wizamart, {{ first_name }}!",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Welcome to Wizamart!</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hi {{ first_name }},</p>

        <p>Thank you for signing up for Wizamart! Your account for <strong>{{ company_name }}</strong> is now active.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #6366f1;">
            <h3 style="margin-top: 0; color: #6366f1;">Your Account Details</h3>
            <p style="margin: 5px 0;"><strong>Vendor Code:</strong> {{ vendor_code }}</p>
            <p style="margin: 5px 0;"><strong>Plan:</strong> {{ tier_name }}</p>
            <p style="margin: 5px 0;"><strong>Trial Period:</strong> {{ trial_days }} days free</p>
        </div>

        <p>You can start managing your orders, inventory, and invoices right away:</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ login_url }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Go to Dashboard
            </a>
        </div>

        <h3 style="color: #374151;">Getting Started</h3>
        <ol style="color: #4b5563;">
            <li>Complete your company profile</li>
            <li>Connect your Letzshop API credentials</li>
            <li>Import your products</li>
            <li>Start syncing orders!</li>
        </ol>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            If you have any questions, just reply to this email or visit our help center.
        </p>

        <p>Best regards,<br><strong>The Wizamart Team</strong></p>
    </div>

    <div style="text-align: center; padding: 20px; color: #9ca3af; font-size: 12px;">
        <p>&copy; 2024 Wizamart. Built for Luxembourg e-commerce.</p>
    </div>
</body>
</html>""",
        "body_text": """Welcome to Wizamart!

Hi {{ first_name }},

Thank you for signing up for Wizamart! Your account for {{ company_name }} is now active.

Your Account Details:
- Vendor Code: {{ vendor_code }}
- Plan: {{ tier_name }}
- Trial Period: {{ trial_days }} days free

You can start managing your orders, inventory, and invoices right away.

Go to Dashboard: {{ login_url }}

Getting Started:
1. Complete your company profile
2. Connect your Letzshop API credentials
3. Import your products
4. Start syncing orders!

If you have any questions, just reply to this email.

Best regards,
The Wizamart Team
""",
    },
    {
        "code": "signup_welcome",
        "language": "fr",
        "name": "Bienvenue après inscription",
        "description": "Envoyé aux nouveaux vendeurs après inscription",
        "category": EmailCategory.AUTH.value,
        "variables": json.dumps([
            "first_name", "company_name", "email", "vendor_code",
            "login_url", "trial_days", "tier_name"
        ]),
        "subject": "Bienvenue sur Wizamart, {{ first_name }} !",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Bienvenue sur Wizamart !</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Bonjour {{ first_name }},</p>

        <p>Merci de vous être inscrit sur Wizamart ! Votre compte pour <strong>{{ company_name }}</strong> est maintenant actif.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #6366f1;">
            <h3 style="margin-top: 0; color: #6366f1;">Détails de votre compte</h3>
            <p style="margin: 5px 0;"><strong>Code vendeur :</strong> {{ vendor_code }}</p>
            <p style="margin: 5px 0;"><strong>Forfait :</strong> {{ tier_name }}</p>
            <p style="margin: 5px 0;"><strong>Période d'essai :</strong> {{ trial_days }} jours gratuits</p>
        </div>

        <p>Vous pouvez commencer à gérer vos commandes, stocks et factures dès maintenant :</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ login_url }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Accéder au tableau de bord
            </a>
        </div>

        <h3 style="color: #374151;">Pour commencer</h3>
        <ol style="color: #4b5563;">
            <li>Complétez votre profil d'entreprise</li>
            <li>Connectez vos identifiants API Letzshop</li>
            <li>Importez vos produits</li>
            <li>Commencez à synchroniser vos commandes !</li>
        </ol>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            Si vous avez des questions, répondez simplement à cet email.
        </p>

        <p>Cordialement,<br><strong>L'équipe Wizamart</strong></p>
    </div>

    <div style="text-align: center; padding: 20px; color: #9ca3af; font-size: 12px;">
        <p>&copy; 2024 Wizamart. Conçu pour le e-commerce luxembourgeois.</p>
    </div>
</body>
</html>""",
        "body_text": """Bienvenue sur Wizamart !

Bonjour {{ first_name }},

Merci de vous être inscrit sur Wizamart ! Votre compte pour {{ company_name }} est maintenant actif.

Détails de votre compte :
- Code vendeur : {{ vendor_code }}
- Forfait : {{ tier_name }}
- Période d'essai : {{ trial_days }} jours gratuits

Accéder au tableau de bord : {{ login_url }}

Pour commencer :
1. Complétez votre profil d'entreprise
2. Connectez vos identifiants API Letzshop
3. Importez vos produits
4. Commencez à synchroniser vos commandes !

Cordialement,
L'équipe Wizamart
""",
    },
    {
        "code": "signup_welcome",
        "language": "de",
        "name": "Willkommen nach Anmeldung",
        "description": "An neue Verkäufer nach erfolgreicher Anmeldung gesendet",
        "category": EmailCategory.AUTH.value,
        "variables": json.dumps([
            "first_name", "company_name", "email", "vendor_code",
            "login_url", "trial_days", "tier_name"
        ]),
        "subject": "Willkommen bei Wizamart, {{ first_name }}!",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Willkommen bei Wizamart!</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hallo {{ first_name }},</p>

        <p>Vielen Dank für Ihre Anmeldung bei Wizamart! Ihr Konto für <strong>{{ company_name }}</strong> ist jetzt aktiv.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #6366f1;">
            <h3 style="margin-top: 0; color: #6366f1;">Ihre Kontodaten</h3>
            <p style="margin: 5px 0;"><strong>Verkäufercode:</strong> {{ vendor_code }}</p>
            <p style="margin: 5px 0;"><strong>Tarif:</strong> {{ tier_name }}</p>
            <p style="margin: 5px 0;"><strong>Testzeitraum:</strong> {{ trial_days }} Tage kostenlos</p>
        </div>

        <p>Sie können sofort mit der Verwaltung Ihrer Bestellungen, Bestände und Rechnungen beginnen:</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ login_url }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Zum Dashboard
            </a>
        </div>

        <h3 style="color: #374151;">Erste Schritte</h3>
        <ol style="color: #4b5563;">
            <li>Vervollständigen Sie Ihr Firmenprofil</li>
            <li>Verbinden Sie Ihre Letzshop API-Zugangsdaten</li>
            <li>Importieren Sie Ihre Produkte</li>
            <li>Starten Sie die Bestellungssynchronisierung!</li>
        </ol>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            Bei Fragen antworten Sie einfach auf diese E-Mail.
        </p>

        <p>Mit freundlichen Grüßen,<br><strong>Das Wizamart-Team</strong></p>
    </div>

    <div style="text-align: center; padding: 20px; color: #9ca3af; font-size: 12px;">
        <p>&copy; 2024 Wizamart. Entwickelt für den luxemburgischen E-Commerce.</p>
    </div>
</body>
</html>""",
        "body_text": """Willkommen bei Wizamart!

Hallo {{ first_name }},

Vielen Dank für Ihre Anmeldung bei Wizamart! Ihr Konto für {{ company_name }} ist jetzt aktiv.

Ihre Kontodaten:
- Verkäufercode: {{ vendor_code }}
- Tarif: {{ tier_name }}
- Testzeitraum: {{ trial_days }} Tage kostenlos

Zum Dashboard: {{ login_url }}

Erste Schritte:
1. Vervollständigen Sie Ihr Firmenprofil
2. Verbinden Sie Ihre Letzshop API-Zugangsdaten
3. Importieren Sie Ihre Produkte
4. Starten Sie die Bestellungssynchronisierung!

Mit freundlichen Grüßen,
Das Wizamart-Team
""",
    },
    {
        "code": "signup_welcome",
        "language": "lb",
        "name": "Wëllkomm no der Umeldung",
        "description": "Un nei Verkeefer no erfollegräicher Umeldung geschéckt",
        "category": EmailCategory.AUTH.value,
        "variables": json.dumps([
            "first_name", "company_name", "email", "vendor_code",
            "login_url", "trial_days", "tier_name"
        ]),
        "subject": "Wëllkomm op Wizamart, {{ first_name }}!",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Wëllkomm op Wizamart!</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Moien {{ first_name }},</p>

        <p>Merci fir d'Umeldung op Wizamart! Äre Kont fir <strong>{{ company_name }}</strong> ass elo aktiv.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #6366f1;">
            <h3 style="margin-top: 0; color: #6366f1;">Är Kontdetailer</h3>
            <p style="margin: 5px 0;"><strong>Verkeefer Code:</strong> {{ vendor_code }}</p>
            <p style="margin: 5px 0;"><strong>Plang:</strong> {{ tier_name }}</p>
            <p style="margin: 5px 0;"><strong>Testperiod:</strong> {{ trial_days }} Deeg gratis</p>
        </div>

        <p>Dir kënnt direkt ufänken Är Bestellungen, Lager a Rechnungen ze verwalten:</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ login_url }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Zum Dashboard
            </a>
        </div>

        <h3 style="color: #374151;">Fir unzefänken</h3>
        <ol style="color: #4b5563;">
            <li>Fëllt Äre Firmeprofil aus</li>
            <li>Verbindt Är Letzshop API Zougangsdaten</li>
            <li>Importéiert Är Produkter</li>
            <li>Fänkt un Bestellungen ze synchroniséieren!</li>
        </ol>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            Wann Dir Froen hutt, äntwert einfach op dës E-Mail.
        </p>

        <p>Mat beschte Gréiss,<br><strong>D'Wizamart Team</strong></p>
    </div>

    <div style="text-align: center; padding: 20px; color: #9ca3af; font-size: 12px;">
        <p>&copy; 2024 Wizamart. Gemaach fir de lëtzebuergeschen E-Commerce.</p>
    </div>
</body>
</html>""",
        "body_text": """Wëllkomm op Wizamart!

Moien {{ first_name }},

Merci fir d'Umeldung op Wizamart! Äre Kont fir {{ company_name }} ass elo aktiv.

Är Kontdetailer:
- Verkeefer Code: {{ vendor_code }}
- Plang: {{ tier_name }}
- Testperiod: {{ trial_days }} Deeg gratis

Zum Dashboard: {{ login_url }}

Fir unzefänken:
1. Fëllt Äre Firmeprofil aus
2. Verbindt Är Letzshop API Zougangsdaten
3. Importéiert Är Produkter
4. Fänkt un Bestellungen ze synchroniséieren!

Mat beschte Gréiss,
D'Wizamart Team
""",
    },
    # -------------------------------------------------------------------------
    # ORDER CONFIRMATION
    # -------------------------------------------------------------------------
    {
        "code": "order_confirmation",
        "language": "en",
        "name": "Order Confirmation",
        "description": "Sent to customers after placing an order",
        "category": EmailCategory.ORDERS.value,
        "variables": json.dumps([
            "customer_name", "order_number", "order_total",
            "order_items_count", "order_date", "shipping_address"
        ]),
        "subject": "Order Confirmation - {{ order_number }}",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Order Confirmed!</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hi {{ customer_name }},</p>

        <p>Thank you for your order! We've received your order and it's being processed.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #10b981;">
            <h3 style="margin-top: 0; color: #10b981;">Order Details</h3>
            <p style="margin: 5px 0;"><strong>Order Number:</strong> {{ order_number }}</p>
            <p style="margin: 5px 0;"><strong>Date:</strong> {{ order_date }}</p>
            <p style="margin: 5px 0;"><strong>Items:</strong> {{ order_items_count }}</p>
            <p style="margin: 5px 0;"><strong>Total:</strong> {{ order_total }}</p>
        </div>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0;">
            <h3 style="margin-top: 0; color: #374151;">Shipping Address</h3>
            <p style="margin: 5px 0;">{{ shipping_address }}</p>
        </div>

        <p>You will receive another email when your order ships.</p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            If you have any questions about your order, please contact us.
        </p>

        <p>Thank you for shopping with us!<br><strong>The Team</strong></p>
    </div>

    <div style="text-align: center; padding: 20px; color: #9ca3af; font-size: 12px;">
        <p>This is an automated email. Please do not reply directly.</p>
    </div>
</body>
</html>""",
        "body_text": """Order Confirmed!

Hi {{ customer_name }},

Thank you for your order! We've received your order and it's being processed.

Order Details:
- Order Number: {{ order_number }}
- Date: {{ order_date }}
- Items: {{ order_items_count }}
- Total: {{ order_total }}

Shipping Address:
{{ shipping_address }}

You will receive another email when your order ships.

Thank you for shopping with us!
""",
    },
    {
        "code": "order_confirmation",
        "language": "fr",
        "name": "Confirmation de commande",
        "description": "Envoyé aux clients après avoir passé une commande",
        "category": EmailCategory.ORDERS.value,
        "variables": json.dumps([
            "customer_name", "order_number", "order_total",
            "order_items_count", "order_date", "shipping_address"
        ]),
        "subject": "Confirmation de commande - {{ order_number }}",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Commande confirmée !</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Bonjour {{ customer_name }},</p>

        <p>Merci pour votre commande ! Nous l'avons bien reçue et elle est en cours de traitement.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #10b981;">
            <h3 style="margin-top: 0; color: #10b981;">Détails de la commande</h3>
            <p style="margin: 5px 0;"><strong>Numéro de commande :</strong> {{ order_number }}</p>
            <p style="margin: 5px 0;"><strong>Date :</strong> {{ order_date }}</p>
            <p style="margin: 5px 0;"><strong>Articles :</strong> {{ order_items_count }}</p>
            <p style="margin: 5px 0;"><strong>Total :</strong> {{ order_total }}</p>
        </div>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0;">
            <h3 style="margin-top: 0; color: #374151;">Adresse de livraison</h3>
            <p style="margin: 5px 0;">{{ shipping_address }}</p>
        </div>

        <p>Vous recevrez un autre email lors de l'expédition de votre commande.</p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            Si vous avez des questions concernant votre commande, n'hésitez pas à nous contacter.
        </p>

        <p>Merci pour votre achat !<br><strong>L'équipe</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Commande confirmée !

Bonjour {{ customer_name }},

Merci pour votre commande ! Nous l'avons bien reçue et elle est en cours de traitement.

Détails de la commande :
- Numéro de commande : {{ order_number }}
- Date : {{ order_date }}
- Articles : {{ order_items_count }}
- Total : {{ order_total }}

Adresse de livraison :
{{ shipping_address }}

Vous recevrez un autre email lors de l'expédition de votre commande.

Merci pour votre achat !
""",
    },
    {
        "code": "order_confirmation",
        "language": "de",
        "name": "Bestellbestätigung",
        "description": "An Kunden nach einer Bestellung gesendet",
        "category": EmailCategory.ORDERS.value,
        "variables": json.dumps([
            "customer_name", "order_number", "order_total",
            "order_items_count", "order_date", "shipping_address"
        ]),
        "subject": "Bestellbestätigung - {{ order_number }}",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Bestellung bestätigt!</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hallo {{ customer_name }},</p>

        <p>Vielen Dank für Ihre Bestellung! Wir haben Ihre Bestellung erhalten und sie wird bearbeitet.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #10b981;">
            <h3 style="margin-top: 0; color: #10b981;">Bestelldetails</h3>
            <p style="margin: 5px 0;"><strong>Bestellnummer:</strong> {{ order_number }}</p>
            <p style="margin: 5px 0;"><strong>Datum:</strong> {{ order_date }}</p>
            <p style="margin: 5px 0;"><strong>Artikel:</strong> {{ order_items_count }}</p>
            <p style="margin: 5px 0;"><strong>Summe:</strong> {{ order_total }}</p>
        </div>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0;">
            <h3 style="margin-top: 0; color: #374151;">Lieferadresse</h3>
            <p style="margin: 5px 0;">{{ shipping_address }}</p>
        </div>

        <p>Sie erhalten eine weitere E-Mail, sobald Ihre Bestellung versandt wird.</p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            Bei Fragen zu Ihrer Bestellung kontaktieren Sie uns bitte.
        </p>

        <p>Vielen Dank für Ihren Einkauf!<br><strong>Das Team</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Bestellung bestätigt!

Hallo {{ customer_name }},

Vielen Dank für Ihre Bestellung! Wir haben Ihre Bestellung erhalten und sie wird bearbeitet.

Bestelldetails:
- Bestellnummer: {{ order_number }}
- Datum: {{ order_date }}
- Artikel: {{ order_items_count }}
- Summe: {{ order_total }}

Lieferadresse:
{{ shipping_address }}

Sie erhalten eine weitere E-Mail, sobald Ihre Bestellung versandt wird.

Vielen Dank für Ihren Einkauf!
""",
    },
    {
        "code": "order_confirmation",
        "language": "lb",
        "name": "Bestellung Konfirmatioun",
        "description": "Un Clienten no enger Bestellung geschéckt",
        "category": EmailCategory.ORDERS.value,
        "variables": json.dumps([
            "customer_name", "order_number", "order_total",
            "order_items_count", "order_date", "shipping_address"
        ]),
        "subject": "Bestellung Konfirmatioun - {{ order_number }}",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Bestellung confirméiert!</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Moien {{ customer_name }},</p>

        <p>Merci fir Är Bestellung! Mir hunn Är Bestellung kritt an si gëtt beaarbecht.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #10b981;">
            <h3 style="margin-top: 0; color: #10b981;">Bestelldetailer</h3>
            <p style="margin: 5px 0;"><strong>Bestellnummer:</strong> {{ order_number }}</p>
            <p style="margin: 5px 0;"><strong>Datum:</strong> {{ order_date }}</p>
            <p style="margin: 5px 0;"><strong>Artikelen:</strong> {{ order_items_count }}</p>
            <p style="margin: 5px 0;"><strong>Total:</strong> {{ order_total }}</p>
        </div>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0;">
            <h3 style="margin-top: 0; color: #374151;">Liwweradress</h3>
            <p style="margin: 5px 0;">{{ shipping_address }}</p>
        </div>

        <p>Dir kritt eng weider E-Mail wann Är Bestellung verschéckt gëtt.</p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            Wann Dir Froen iwwer Är Bestellung hutt, kontaktéiert eis w.e.g.
        </p>

        <p>Merci fir Ären Akaf!<br><strong>D'Team</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Bestellung confirméiert!

Moien {{ customer_name }},

Merci fir Är Bestellung! Mir hunn Är Bestellung kritt an si gëtt beaarbecht.

Bestelldetailer:
- Bestellnummer: {{ order_number }}
- Datum: {{ order_date }}
- Artikelen: {{ order_items_count }}
- Total: {{ order_total }}

Liwweradress:
{{ shipping_address }}

Dir kritt eng weider E-Mail wann Är Bestellung verschéckt gëtt.

Merci fir Ären Akaf!
""",
    },
    # -------------------------------------------------------------------------
    # PASSWORD RESET
    # -------------------------------------------------------------------------
    {
        "code": "password_reset",
        "language": "en",
        "name": "Password Reset",
        "description": "Sent to customers when they request a password reset",
        "category": EmailCategory.AUTH.value,
        "variables": json.dumps([
            "customer_name", "reset_link", "expiry_hours"
        ]),
        "subject": "Reset Your Password",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Reset Your Password</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hi {{ customer_name }},</p>

        <p>We received a request to reset your password. Click the button below to create a new password:</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ reset_link }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Reset Password
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px;">
            This link will expire in {{ expiry_hours }} hour(s). If you didn't request this password reset, you can safely ignore this email.
        </p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 20px;">
            If the button doesn't work, copy and paste this link into your browser:<br>
            <a href="{{ reset_link }}" style="color: #6366f1; word-break: break-all;">{{ reset_link }}</a>
        </p>

        <p style="margin-top: 30px;">Best regards,<br><strong>The Team</strong></p>
    </div>

    <div style="text-align: center; padding: 20px; color: #9ca3af; font-size: 12px;">
        <p>This is an automated email. Please do not reply directly.</p>
    </div>
</body>
</html>""",
        "body_text": """Reset Your Password

Hi {{ customer_name }},

We received a request to reset your password. Click the link below to create a new password:

{{ reset_link }}

This link will expire in {{ expiry_hours }} hour(s). If you didn't request this password reset, you can safely ignore this email.

Best regards,
The Team
""",
    },
    {
        "code": "password_reset",
        "language": "fr",
        "name": "Reinitialisation du mot de passe",
        "description": "Envoye aux clients lorsqu'ils demandent une reinitialisation de mot de passe",
        "category": EmailCategory.AUTH.value,
        "variables": json.dumps([
            "customer_name", "reset_link", "expiry_hours"
        ]),
        "subject": "Reinitialiser votre mot de passe",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Reinitialiser votre mot de passe</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Bonjour {{ customer_name }},</p>

        <p>Nous avons recu une demande de reinitialisation de votre mot de passe. Cliquez sur le bouton ci-dessous pour creer un nouveau mot de passe :</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ reset_link }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Reinitialiser le mot de passe
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px;">
            Ce lien expirera dans {{ expiry_hours }} heure(s). Si vous n'avez pas demande cette reinitialisation, vous pouvez ignorer cet email.
        </p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 20px;">
            Si le bouton ne fonctionne pas, copiez et collez ce lien dans votre navigateur :<br>
            <a href="{{ reset_link }}" style="color: #6366f1; word-break: break-all;">{{ reset_link }}</a>
        </p>

        <p style="margin-top: 30px;">Cordialement,<br><strong>L'equipe</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Reinitialiser votre mot de passe

Bonjour {{ customer_name }},

Nous avons recu une demande de reinitialisation de votre mot de passe. Cliquez sur le lien ci-dessous pour creer un nouveau mot de passe :

{{ reset_link }}

Ce lien expirera dans {{ expiry_hours }} heure(s). Si vous n'avez pas demande cette reinitialisation, vous pouvez ignorer cet email.

Cordialement,
L'equipe
""",
    },
    {
        "code": "password_reset",
        "language": "de",
        "name": "Passwort zurucksetzen",
        "description": "An Kunden gesendet, wenn sie eine Passwortzurucksetzung anfordern",
        "category": EmailCategory.AUTH.value,
        "variables": json.dumps([
            "customer_name", "reset_link", "expiry_hours"
        ]),
        "subject": "Passwort zurucksetzen",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Passwort zurucksetzen</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hallo {{ customer_name }},</p>

        <p>Wir haben eine Anfrage zur Zurucksetzung Ihres Passworts erhalten. Klicken Sie auf die Schaltflache unten, um ein neues Passwort zu erstellen:</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ reset_link }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Passwort zurucksetzen
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px;">
            Dieser Link lauft in {{ expiry_hours }} Stunde(n) ab. Wenn Sie diese Passwortzurucksetzung nicht angefordert haben, konnen Sie diese E-Mail ignorieren.
        </p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 20px;">
            Wenn die Schaltflache nicht funktioniert, kopieren Sie diesen Link in Ihren Browser:<br>
            <a href="{{ reset_link }}" style="color: #6366f1; word-break: break-all;">{{ reset_link }}</a>
        </p>

        <p style="margin-top: 30px;">Mit freundlichen Grussen,<br><strong>Das Team</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Passwort zurucksetzen

Hallo {{ customer_name }},

Wir haben eine Anfrage zur Zurucksetzung Ihres Passworts erhalten. Klicken Sie auf den Link unten, um ein neues Passwort zu erstellen:

{{ reset_link }}

Dieser Link lauft in {{ expiry_hours }} Stunde(n) ab. Wenn Sie diese Passwortzurucksetzung nicht angefordert haben, konnen Sie diese E-Mail ignorieren.

Mit freundlichen Grussen,
Das Team
""",
    },
    {
        "code": "password_reset",
        "language": "lb",
        "name": "Passwuert zrecksetzen",
        "description": "Un Clienten gescheckt wann si eng Passwuertzrecksetzung ufroen",
        "category": EmailCategory.AUTH.value,
        "variables": json.dumps([
            "customer_name", "reset_link", "expiry_hours"
        ]),
        "subject": "Passwuert zrecksetzen",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Passwuert zrecksetzen</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Moien {{ customer_name }},</p>

        <p>Mir hunn eng Ufro kritt fir Aert Passwuert zreckzesetzen. Klickt op de Knäppchen hei drënner fir en neit Passwuert ze kreéieren:</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ reset_link }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Passwuert zrecksetzen
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px;">
            Dëse Link leeft an {{ expiry_hours }} Stonn(en) of. Wann Dir dës Passwuertzrecksetzung net ugefrot hutt, kënnt Dir dës E-Mail ignoréieren.
        </p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 20px;">
            Wann de Knäppchen net fonctionnéiert, kopéiert dëse Link an Äre Browser:<br>
            <a href="{{ reset_link }}" style="color: #6366f1; word-break: break-all;">{{ reset_link }}</a>
        </p>

        <p style="margin-top: 30px;">Mat beschte Gréiss,<br><strong>D'Team</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Passwuert zrecksetzen

Moien {{ customer_name }},

Mir hunn eng Ufro kritt fir Aert Passwuert zreckzesetzen. Klickt op de Link hei drënner fir en neit Passwuert ze kreéieren:

{{ reset_link }}

Dëse Link leeft an {{ expiry_hours }} Stonn(en) of. Wann Dir dës Passwuertzrecksetzung net ugefrot hutt, kënnt Dir dës E-Mail ignoréieren.

Mat beschte Gréiss,
D'Team
""",
    },
    # -------------------------------------------------------------------------
    # PLATFORM-ONLY BILLING TEMPLATES
    # -------------------------------------------------------------------------
    {
        "code": "subscription_welcome",
        "language": "en",
        "name": "Subscription Welcome",
        "description": "Sent to vendors when they subscribe to a paid plan",
        "category": EmailCategory.BILLING.value,
        "is_platform_only": True,
        "required_variables": json.dumps(["vendor_name", "tier_name", "billing_cycle", "amount"]),
        "variables": json.dumps([
            "vendor_name", "tier_name", "billing_cycle", "amount",
            "next_billing_date", "dashboard_url"
        ]),
        "subject": "Welcome to {{ tier_name }} - Subscription Confirmed",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #10b981 0%, #059669 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Subscription Confirmed!</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hi {{ vendor_name }},</p>

        <p>Thank you for subscribing to Wizamart! Your {{ tier_name }} subscription is now active.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #10b981;">
            <h3 style="margin-top: 0; color: #10b981;">Subscription Details</h3>
            <p style="margin: 5px 0;"><strong>Plan:</strong> {{ tier_name }}</p>
            <p style="margin: 5px 0;"><strong>Billing Cycle:</strong> {{ billing_cycle }}</p>
            <p style="margin: 5px 0;"><strong>Amount:</strong> {{ amount }}</p>
            <p style="margin: 5px 0;"><strong>Next Billing Date:</strong> {{ next_billing_date }}</p>
        </div>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ dashboard_url }}" style="background: #10b981; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Go to Dashboard
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            If you have any questions about your subscription, please contact our support team.
        </p>

        <p>Best regards,<br><strong>The Wizamart Team</strong></p>
    </div>

    <div style="text-align: center; padding: 20px; color: #9ca3af; font-size: 12px;">
        <p>&copy; 2024 Wizamart. All rights reserved.</p>
    </div>
</body>
</html>""",
        "body_text": """Subscription Confirmed!

Hi {{ vendor_name }},

Thank you for subscribing to Wizamart! Your {{ tier_name }} subscription is now active.

Subscription Details:
- Plan: {{ tier_name }}
- Billing Cycle: {{ billing_cycle }}
- Amount: {{ amount }}
- Next Billing Date: {{ next_billing_date }}

Go to Dashboard: {{ dashboard_url }}

If you have any questions about your subscription, please contact our support team.

Best regards,
The Wizamart Team
""",
    },
    {
        "code": "payment_failed",
        "language": "en",
        "name": "Payment Failed",
        "description": "Sent when a subscription payment fails",
        "category": EmailCategory.BILLING.value,
        "is_platform_only": True,
        "required_variables": json.dumps(["vendor_name", "tier_name", "amount"]),
        "variables": json.dumps([
            "vendor_name", "tier_name", "amount", "retry_date",
            "update_payment_url", "support_email"
        ]),
        "subject": "Action Required: Payment Failed for Your Subscription",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Payment Failed</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hi {{ vendor_name }},</p>

        <p>We were unable to process your payment of <strong>{{ amount }}</strong> for your {{ tier_name }} subscription.</p>

        <div style="background: #fef2f2; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #ef4444;">
            <h3 style="margin-top: 0; color: #dc2626;">What happens next?</h3>
            <p style="margin: 5px 0;">We'll automatically retry the payment on {{ retry_date }}.</p>
            <p style="margin: 5px 0;">To avoid any service interruption, please update your payment method.</p>
        </div>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ update_payment_url }}" style="background: #ef4444; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Update Payment Method
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            If you need assistance, please contact us at {{ support_email }}.
        </p>

        <p>Best regards,<br><strong>The Wizamart Team</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Payment Failed

Hi {{ vendor_name }},

We were unable to process your payment of {{ amount }} for your {{ tier_name }} subscription.

What happens next?
- We'll automatically retry the payment on {{ retry_date }}.
- To avoid any service interruption, please update your payment method.

Update Payment Method: {{ update_payment_url }}

If you need assistance, please contact us at {{ support_email }}.

Best regards,
The Wizamart Team
""",
    },
    {
        "code": "subscription_cancelled",
        "language": "en",
        "name": "Subscription Cancelled",
        "description": "Sent when a subscription is cancelled",
        "category": EmailCategory.BILLING.value,
        "is_platform_only": True,
        "required_variables": json.dumps(["vendor_name", "tier_name"]),
        "variables": json.dumps([
            "vendor_name", "tier_name", "end_date", "reactivate_url"
        ]),
        "subject": "Your Wizamart Subscription Has Been Cancelled",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Subscription Cancelled</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hi {{ vendor_name }},</p>

        <p>Your {{ tier_name }} subscription has been cancelled as requested.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #6b7280;">
            <h3 style="margin-top: 0; color: #4b5563;">What happens now?</h3>
            <p style="margin: 5px 0;">You'll continue to have access to your {{ tier_name }} features until <strong>{{ end_date }}</strong>.</p>
            <p style="margin: 5px 0;">After that date, your account will be downgraded to the Free tier.</p>
        </div>

        <p>Changed your mind? You can reactivate your subscription at any time:</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ reactivate_url }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Reactivate Subscription
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            We're sorry to see you go. If there's anything we could have done better, please let us know.
        </p>

        <p>Best regards,<br><strong>The Wizamart Team</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Subscription Cancelled

Hi {{ vendor_name }},

Your {{ tier_name }} subscription has been cancelled as requested.

What happens now?
- You'll continue to have access to your {{ tier_name }} features until {{ end_date }}.
- After that date, your account will be downgraded to the Free tier.

Changed your mind? You can reactivate your subscription at any time:
{{ reactivate_url }}

We're sorry to see you go. If there's anything we could have done better, please let us know.

Best regards,
The Wizamart Team
""",
    },
    {
        "code": "trial_ending",
        "language": "en",
        "name": "Trial Ending Soon",
        "description": "Sent when a trial is about to end",
        "category": EmailCategory.BILLING.value,
        "is_platform_only": True,
        "required_variables": json.dumps(["vendor_name", "days_remaining"]),
        "variables": json.dumps([
            "vendor_name", "tier_name", "days_remaining", "trial_end_date",
            "upgrade_url", "features_list"
        ]),
        "subject": "Your Trial Ends in {{ days_remaining }} Days",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">Your Trial is Ending Soon</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hi {{ vendor_name }},</p>

        <p>Your {{ tier_name }} trial ends in <strong>{{ days_remaining }} days</strong> ({{ trial_end_date }}).</p>

        <div style="background: #fffbeb; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #f59e0b;">
            <h3 style="margin-top: 0; color: #d97706;">Don't lose these features:</h3>
            <p style="margin: 5px 0;">{{ features_list }}</p>
        </div>

        <p>Subscribe now to continue using all {{ tier_name }} features without interruption:</p>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ upgrade_url }}" style="background: #f59e0b; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Subscribe Now
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px; margin-top: 30px;">
            Have questions? Reply to this email and we'll help you choose the right plan.
        </p>

        <p>Best regards,<br><strong>The Wizamart Team</strong></p>
    </div>
</body>
</html>""",
        "body_text": """Your Trial is Ending Soon

Hi {{ vendor_name }},

Your {{ tier_name }} trial ends in {{ days_remaining }} days ({{ trial_end_date }}).

Don't lose these features:
{{ features_list }}

Subscribe now to continue using all {{ tier_name }} features without interruption:
{{ upgrade_url }}

Have questions? Reply to this email and we'll help you choose the right plan.

Best regards,
The Wizamart Team
""",
    },
    {
        "code": "team_invite",
        "language": "en",
        "name": "Team Member Invitation",
        "description": "Sent when a vendor invites a team member",
        "category": EmailCategory.SYSTEM.value,
        "is_platform_only": False,
        "required_variables": json.dumps(["invitee_name", "inviter_name", "vendor_name", "accept_url"]),
        "variables": json.dumps([
            "invitee_name", "inviter_name", "vendor_name", "role",
            "accept_url", "expires_in_days"
        ]),
        "subject": "{{ inviter_name }} invited you to join {{ vendor_name }} on Wizamart",
        "body_html": """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px;">
    <div style="background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); padding: 30px; border-radius: 10px 10px 0 0;">
        <h1 style="color: white; margin: 0; font-size: 28px;">You've Been Invited!</h1>
    </div>

    <div style="background: #f9fafb; padding: 30px; border-radius: 0 0 10px 10px;">
        <p style="font-size: 16px;">Hi {{ invitee_name }},</p>

        <p><strong>{{ inviter_name }}</strong> has invited you to join <strong>{{ vendor_name }}</strong> as a team member on Wizamart.</p>

        <div style="background: white; border-radius: 8px; padding: 20px; margin: 20px 0; border-left: 4px solid #6366f1;">
            <h3 style="margin-top: 0; color: #6366f1;">Invitation Details</h3>
            <p style="margin: 5px 0;"><strong>Vendor:</strong> {{ vendor_name }}</p>
            <p style="margin: 5px 0;"><strong>Role:</strong> {{ role }}</p>
            <p style="margin: 5px 0;"><strong>Invited by:</strong> {{ inviter_name }}</p>
        </div>

        <div style="text-align: center; margin: 30px 0;">
            <a href="{{ accept_url }}" style="background: #6366f1; color: white; padding: 14px 28px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block;">
                Accept Invitation
            </a>
        </div>

        <p style="color: #6b7280; font-size: 14px;">
            This invitation will expire in {{ expires_in_days }} days.
        </p>

        <p style="color: #6b7280; font-size: 14px; margin-top: 20px;">
            If you weren't expecting this invitation, you can safely ignore this email.
        </p>

        <p>Best regards,<br><strong>The Wizamart Team</strong></p>
    </div>
</body>
</html>""",
        "body_text": """You've Been Invited!

Hi {{ invitee_name }},

{{ inviter_name }} has invited you to join {{ vendor_name }} as a team member on Wizamart.

Invitation Details:
- Vendor: {{ vendor_name }}
- Role: {{ role }}
- Invited by: {{ inviter_name }}

Accept Invitation: {{ accept_url }}

This invitation will expire in {{ expires_in_days }} days.

If you weren't expecting this invitation, you can safely ignore this email.

Best regards,
The Wizamart Team
""",
    },
]


def seed_templates():
    """Seed email templates into database."""
    db = next(get_db())

    try:
        created = 0
        updated = 0

        for template_data in TEMPLATES:
            # Set defaults for new fields
            template_data.setdefault("is_platform_only", False)
            template_data.setdefault("required_variables", None)

            # Check if template already exists
            existing = (
                db.query(EmailTemplate)
                .filter(
                    EmailTemplate.code == template_data["code"],
                    EmailTemplate.language == template_data["language"],
                )
                .first()
            )

            if existing:
                # Update existing template
                for key, value in template_data.items():
                    setattr(existing, key, value)
                updated += 1
                platform_only_tag = " [platform-only]" if template_data.get("is_platform_only") else ""
                print(f"Updated: {template_data['code']} ({template_data['language']}){platform_only_tag}")
            else:
                # Create new template
                template = EmailTemplate(**template_data)
                db.add(template)
                created += 1
                platform_only_tag = " [platform-only]" if template_data.get("is_platform_only") else ""
                print(f"Created: {template_data['code']} ({template_data['language']}){platform_only_tag}")

        db.commit()
        print(f"\nDone! Created: {created}, Updated: {updated}")

    except Exception as e:
        db.rollback()
        print(f"Error: {e}")
        raise
    finally:
        db.close()


if __name__ == "__main__":
    seed_templates()
