-- ============================================
-- TEMPLATE-SAAS: Production Seeds - Notification Templates
-- Version: 1.0.0
-- ============================================

INSERT INTO notifications.templates (id, code, name, description, category, channel, subject, body, body_html, variables) VALUES

-- Welcome email
(
    'b0000001-0000-0000-0000-000000000001',
    'welcome_email',
    'Welcome Email',
    'Sent when a new user registers',
    'transactional',
    'email',
    'Welcome to {{company_name}}!',
    'Hi {{user_name}},

Welcome to {{company_name}}! We''re excited to have you on board.

Your account has been created successfully. Here''s what you can do next:

1. Complete your profile
2. Explore the dashboard
3. Invite your team members

If you have any questions, feel free to reach out to our support team.

Best regards,
The {{company_name}} Team',
    '<h1>Welcome to {{company_name}}!</h1>
<p>Hi {{user_name}},</p>
<p>Welcome to {{company_name}}! We''re excited to have you on board.</p>
<p>Your account has been created successfully. Here''s what you can do next:</p>
<ol>
<li>Complete your profile</li>
<li>Explore the dashboard</li>
<li>Invite your team members</li>
</ol>
<p>If you have any questions, feel free to reach out to our support team.</p>
<p>Best regards,<br>The {{company_name}} Team</p>',
    '[{"name": "user_name", "required": true}, {"name": "company_name", "required": true, "default": "Template SaaS"}]'
),

-- Email verification
(
    'b0000001-0000-0000-0000-000000000002',
    'email_verification',
    'Email Verification',
    'Sent to verify email address',
    'transactional',
    'email',
    'Verify your email address',
    'Hi {{user_name}},

Please verify your email address by clicking the link below:

{{verification_link}}

This link will expire in {{expiry_hours}} hours.

If you didn''t create an account, you can safely ignore this email.

Best regards,
The {{company_name}} Team',
    '<h2>Verify your email address</h2>
<p>Hi {{user_name}},</p>
<p>Please verify your email address by clicking the button below:</p>
<p><a href="{{verification_link}}" style="background-color: #4F46E5; color: white; padding: 12px 24px; text-decoration: none; border-radius: 6px;">Verify Email</a></p>
<p>This link will expire in {{expiry_hours}} hours.</p>
<p>If you didn''t create an account, you can safely ignore this email.</p>',
    '[{"name": "user_name", "required": true}, {"name": "verification_link", "required": true}, {"name": "expiry_hours", "required": true, "default": "24"}, {"name": "company_name", "required": true, "default": "Template SaaS"}]'
),

-- Password reset
(
    'b0000001-0000-0000-0000-000000000003',
    'password_reset',
    'Password Reset',
    'Sent when user requests password reset',
    'transactional',
    'email',
    'Reset your password',
    'Hi {{user_name}},

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

{{reset_link}}

This link will expire in {{expiry_hours}} hours.

If you didn''t request this, you can safely ignore this email. Your password will not be changed.

Best regards,
The {{company_name}} Team',
    '<h2>Reset your password</h2>
<p>Hi {{user_name}},</p>
<p>We received a request to reset your password. Click the button below to set a new password:</p>
<p><a href="{{reset_link}}" style="background-color: #4F46E5; color: white; padding: 12px 24px; text-decoration: none; border-radius: 6px;">Reset Password</a></p>
<p>This link will expire in {{expiry_hours}} hours.</p>
<p>If you didn''t request this, you can safely ignore this email.</p>',
    '[{"name": "user_name", "required": true}, {"name": "reset_link", "required": true}, {"name": "expiry_hours", "required": true, "default": "1"}, {"name": "company_name", "required": true, "default": "Template SaaS"}]'
),

-- User invitation
(
    'b0000001-0000-0000-0000-000000000004',
    'user_invitation',
    'User Invitation',
    'Sent when inviting a new team member',
    'transactional',
    'email',
    'You''ve been invited to join {{tenant_name}}',
    'Hi,

{{inviter_name}} has invited you to join {{tenant_name}} on {{company_name}}.

Click the link below to accept the invitation and create your account:

{{invitation_link}}

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

Best regards,
The {{company_name}} Team',
    '<h2>You''ve been invited!</h2>
<p><strong>{{inviter_name}}</strong> has invited you to join <strong>{{tenant_name}}</strong> on {{company_name}}.</p>
<p><a href="{{invitation_link}}" style="background-color: #4F46E5; color: white; padding: 12px 24px; text-decoration: none; border-radius: 6px;">Accept Invitation</a></p>
<p>This invitation will expire in {{expiry_days}} days.</p>',
    '[{"name": "inviter_name", "required": true}, {"name": "tenant_name", "required": true}, {"name": "invitation_link", "required": true}, {"name": "expiry_days", "required": true, "default": "7"}, {"name": "company_name", "required": true, "default": "Template SaaS"}]'
),

-- Invoice paid
(
    'b0000001-0000-0000-0000-000000000005',
    'invoice_paid',
    'Invoice Paid',
    'Sent when an invoice is paid',
    'transactional',
    'email',
    'Payment received - Invoice #{{invoice_number}}',
    'Hi {{user_name}},

We''ve received your payment for invoice #{{invoice_number}}.

Amount: {{amount}} {{currency}}
Date: {{payment_date}}

You can download your receipt here: {{receipt_link}}

Thank you for your business!

Best regards,
The {{company_name}} Team',
    '<h2>Payment Received</h2>
<p>Hi {{user_name}},</p>
<p>We''ve received your payment for invoice #{{invoice_number}}.</p>
<table style="margin: 20px 0;">
<tr><td><strong>Amount:</strong></td><td>{{amount}} {{currency}}</td></tr>
<tr><td><strong>Date:</strong></td><td>{{payment_date}}</td></tr>
</table>
<p><a href="{{receipt_link}}">Download Receipt</a></p>
<p>Thank you for your business!</p>',
    '[{"name": "user_name", "required": true}, {"name": "invoice_number", "required": true}, {"name": "amount", "required": true}, {"name": "currency", "required": true, "default": "USD"}, {"name": "payment_date", "required": true}, {"name": "receipt_link", "required": true}, {"name": "company_name", "required": true, "default": "Template SaaS"}]'
),

-- Trial ending soon
(
    'b0000001-0000-0000-0000-000000000006',
    'trial_ending',
    'Trial Ending Soon',
    'Sent when trial is about to end',
    'transactional',
    'email',
    'Your trial ends in {{days_left}} days',
    'Hi {{user_name}},

Your free trial of {{company_name}} ends in {{days_left}} days.

To continue using all features without interruption, please add a payment method and choose a plan.

{{upgrade_link}}

If you have any questions, our team is here to help!

Best regards,
The {{company_name}} Team',
    '<h2>Your trial is ending soon</h2>
<p>Hi {{user_name}},</p>
<p>Your free trial of {{company_name}} ends in <strong>{{days_left}} days</strong>.</p>
<p>To continue using all features without interruption, please add a payment method and choose a plan.</p>
<p><a href="{{upgrade_link}}" style="background-color: #4F46E5; color: white; padding: 12px 24px; text-decoration: none; border-radius: 6px;">Choose a Plan</a></p>',
    '[{"name": "user_name", "required": true}, {"name": "days_left", "required": true}, {"name": "upgrade_link", "required": true}, {"name": "company_name", "required": true, "default": "Template SaaS"}]'
)

ON CONFLICT (code) DO UPDATE SET
    name = EXCLUDED.name,
    subject = EXCLUDED.subject,
    body = EXCLUDED.body,
    body_html = EXCLUDED.body_html,
    updated_at = NOW();

-- Comments
COMMENT ON TABLE notifications.templates IS 'Email and notification templates';
