"""
Default Email Templates

Provides default Puck templates for all email types.
These are used when a tenant hasn't customized their templates.
"""

DEFAULT_TEMPLATES = {
    # =========================================================================
    # Welcome
    # =========================================================================
    'welcome': {
        'subject_template': 'Welcome to {{ business_name }}!',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {
                        'businessName': '{{ business_name }}',
                        'preheader': "We're excited to have you!"
                    }
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Welcome, {{ customer_first_name }}!',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': "Thank you for choosing {{ business_name }}. We're thrilled to have you as a customer and look forward to serving you.",
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Book Your First Appointment',
                        'href': '{{ business_website_url }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailSpacer',
                    'props': {'size': 'md'}
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': "If you have any questions, don't hesitate to reach out to us at {{ business_email }} or call {{ business_phone }}.",
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'address': '{{ business_address }}',
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}',
                        'website': '{{ business_website_url }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Appointment Confirmation
    # =========================================================================
    'appointment_confirmation': {
        'subject_template': 'Appointment Confirmed - {{ service_name }} on {{ appointment_date }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {
                        'businessName': '{{ business_name }}',
                        'preheader': 'Your appointment has been confirmed'
                    }
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Your Appointment is Confirmed!',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nGreat news! Your appointment has been confirmed. Here are the details:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>Service:</strong> {{ service_name }}<br><strong>Date:</strong> {{ appointment_date }}<br><strong>Time:</strong> {{ appointment_time }}<br><strong>Staff:</strong> {{ staff_name }}<br><strong>Location:</strong> {{ location_name }}',
                        'backgroundColor': '#f3f4f6'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Manage Appointment',
                        'href': '{{ manage_appointment_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailSpacer',
                    'props': {'size': 'sm'}
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Add to Calendar',
                        'href': '{{ add_to_calendar_link }}',
                        'variant': 'secondary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailSpacer',
                    'props': {'size': 'md'}
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Need to make changes? You can reschedule or cancel your appointment using the link above.',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'address': '{{ business_address }}',
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Appointment Reminder
    # =========================================================================
    'appointment_reminder': {
        'subject_template': 'Reminder: Your appointment tomorrow at {{ appointment_time }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {
                        'businessName': '{{ business_name }}',
                        'preheader': "Don't forget your appointment tomorrow!"
                    }
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Appointment Reminder',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nThis is a friendly reminder about your upcoming appointment:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>{{ service_name }}</strong><br>{{ appointment_date }} at {{ appointment_time }}<br>with {{ staff_name }}<br><br>{{ location_name }}<br>{{ location_address }}',
                        'backgroundColor': '#fef3c7'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'View Appointment Details',
                        'href': '{{ manage_appointment_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailSpacer',
                    'props': {'size': 'md'}
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': "Can't make it? Please let us know as soon as possible so we can reschedule.",
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Reschedule',
                        'href': '{{ reschedule_link }}',
                        'variant': 'secondary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Appointment Rescheduled
    # =========================================================================
    'appointment_rescheduled': {
        'subject_template': 'Appointment Rescheduled - New time: {{ appointment_date }} at {{ appointment_time }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Your Appointment Has Been Rescheduled',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nYour appointment has been rescheduled. Here are your new appointment details:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>New Date & Time:</strong><br>{{ appointment_date }} at {{ appointment_time }}<br><br><strong>Service:</strong> {{ service_name }}<br><strong>Staff:</strong> {{ staff_name }}<br><strong>Location:</strong> {{ location_name }}',
                        'backgroundColor': '#dbeafe'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'View Appointment',
                        'href': '{{ manage_appointment_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Appointment Cancelled
    # =========================================================================
    'appointment_cancelled': {
        'subject_template': 'Appointment Cancelled - {{ service_name }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Appointment Cancelled',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nYour appointment has been cancelled:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>{{ service_name }}</strong><br>Originally scheduled for {{ appointment_date }} at {{ appointment_time }}',
                        'backgroundColor': '#fee2e2'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': "We'd love to see you again! Feel free to book a new appointment at your convenience.",
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Book New Appointment',
                        'href': '{{ business_website_url }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Thank You / Follow-up
    # =========================================================================
    'thank_you': {
        'subject_template': 'Thank you for visiting {{ business_name }}!',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Thank You, {{ customer_first_name }}!',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Thank you for your recent visit to {{ business_name }}. We hope you had a great experience!\n\nYour feedback means the world to us. If you have a moment, we would love to hear about your experience.',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Leave a Review',
                        'href': '{{ review_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailSpacer',
                    'props': {'size': 'md'}
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Ready to book your next appointment?',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Book Again',
                        'href': '{{ business_website_url }}',
                        'variant': 'secondary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'address': '{{ business_address }}',
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Contract Signing Request
    # =========================================================================
    'contract_signing_request': {
        'subject_template': 'Please Sign: {{ contract_title }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Document Ready for Signature',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\n{{ business_name }} has sent you a document that requires your signature:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>{{ contract_title }}</strong><br><br>{{ contract_description }}',
                        'backgroundColor': '#f3f4f6'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Review & Sign',
                        'href': '{{ signing_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailSpacer',
                    'props': {'size': 'md'}
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Please sign by {{ contract_expires_at }} to avoid any delays.',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Contract Reminder
    # =========================================================================
    'contract_reminder': {
        'subject_template': 'Reminder: Please sign {{ contract_title }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Signature Reminder',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nThis is a friendly reminder that the following document is still awaiting your signature:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>{{ contract_title }}</strong><br><br>Expires in {{ days_until_expiry }} days',
                        'backgroundColor': '#fef3c7'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Sign Now',
                        'href': '{{ signing_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Contract Signed
    # =========================================================================
    'contract_signed': {
        'subject_template': 'Contract Signed: {{ contract_title }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Contract Successfully Signed',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nThank you for signing the following document:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>{{ contract_title }}</strong><br><br>Signed on: {{ signed_at }}',
                        'backgroundColor': '#d1fae5'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'A copy of the signed document has been saved for your records. If you have any questions, please contact us.',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Payment Receipt
    # =========================================================================
    'payment_receipt': {
        'subject_template': 'Payment Receipt from {{ business_name }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Payment Received',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nThank you for your payment. Here is your receipt:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>Amount Paid:</strong> {{ amount_paid }}<br><strong>Invoice:</strong> {{ invoice_number }}<br><strong>Date:</strong> {{ current_date }}',
                        'backgroundColor': '#d1fae5'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'View Receipt',
                        'href': '{{ receipt_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'address': '{{ business_address }}',
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Invoice
    # =========================================================================
    'invoice': {
        'subject_template': 'Invoice {{ invoice_number }} from {{ business_name }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Invoice',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nPlease find your invoice below:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>Invoice #:</strong> {{ invoice_number }}<br><strong>Amount Due:</strong> {{ amount_due }}<br><strong>Due Date:</strong> {{ payment_due_date }}',
                        'backgroundColor': '#f3f4f6'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Pay Now',
                        'href': '{{ payment_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'address': '{{ business_address }}',
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Payment Reminder
    # =========================================================================
    'payment_reminder': {
        'subject_template': 'Payment Reminder: Invoice {{ invoice_number }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Payment Reminder',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nThis is a friendly reminder that payment is due for the following invoice:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>Invoice #:</strong> {{ invoice_number }}<br><strong>Amount Due:</strong> {{ amount_due }}<br><strong>Due Date:</strong> {{ payment_due_date }}',
                        'backgroundColor': '#fef3c7'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'Pay Now',
                        'href': '{{ payment_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'If you have already made this payment, please disregard this reminder.',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Ticket Assigned
    # =========================================================================
    'ticket_assigned': {
        'subject_template': '[Ticket #{{ ticket_id }}] Assigned: {{ ticket_subject }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'New Ticket Assigned',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ assignee_name }},\n\nA support ticket has been assigned to you:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>Ticket #{{ ticket_id }}</strong><br><strong>Subject:</strong> {{ ticket_subject }}<br><strong>Priority:</strong> {{ ticket_priority }}<br><br>{{ ticket_message }}',
                        'backgroundColor': '#f3f4f6'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'View Ticket',
                        'href': '{{ ticket_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {}
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Ticket Reply
    # =========================================================================
    'ticket_reply': {
        'subject_template': 'Re: [Ticket #{{ ticket_id }}] {{ ticket_subject }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'New Reply on Your Ticket',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nThere is a new reply on your support ticket:',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>Ticket #{{ ticket_id }}: {{ ticket_subject }}</strong><br><br>{{ reply_message }}',
                        'backgroundColor': '#f3f4f6'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'View & Reply',
                        'href': '{{ ticket_link }}',
                        'variant': 'primary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'You can also reply directly to this email.',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },

    # =========================================================================
    # Ticket Resolved
    # =========================================================================
    'ticket_resolved': {
        'subject_template': '[Ticket #{{ ticket_id }}] Resolved: {{ ticket_subject }}',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailHeading',
                    'props': {
                        'text': 'Your Ticket Has Been Resolved',
                        'level': 'h1',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': 'Hi {{ customer_first_name }},\n\nGreat news! Your support ticket has been resolved.',
                        'align': 'left'
                    }
                },
                {
                    'type': 'EmailPanel',
                    'props': {
                        'content': '<strong>Ticket #{{ ticket_id }}</strong><br>{{ ticket_subject }}<br><br><strong>Status:</strong> Resolved',
                        'backgroundColor': '#d1fae5'
                    }
                },
                {
                    'type': 'EmailText',
                    'props': {
                        'content': "If you need further assistance or have any questions, don't hesitate to reach out.",
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailButton',
                    'props': {
                        'text': 'View Ticket',
                        'href': '{{ ticket_link }}',
                        'variant': 'secondary',
                        'align': 'center'
                    }
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    },
}


def get_default_template(email_type: str) -> dict:
    """Get the default template for an email type."""
    return DEFAULT_TEMPLATES.get(email_type, {
        'subject_template': f'{email_type.replace("_", " ").title()} Email',
        'puck_data': {
            'content': [
                {
                    'type': 'EmailHeader',
                    'props': {'businessName': '{{ business_name }}'}
                },
                {
                    'type': 'EmailText',
                    'props': {'content': 'Hello {{ customer_first_name }},'}
                },
                {
                    'type': 'EmailFooter',
                    'props': {
                        'phone': '{{ business_phone }}',
                        'email': '{{ business_email }}'
                    }
                }
            ],
            'root': {}
        }
    })
