-- =============================================================================
-- MIGRATION 015: Email notification for student already assigned to another tutor
-- =============================================================================

INSERT INTO public.email_templates (template_key, language, subject, body_html, body_text)
VALUES (
  'STUDENT_CONFLICT', 'es',
  'Aviso: alumno ya asignado a otro tutor',
  '<p>Hola,</p>
   <p>El tutor <strong>{{tutor_name}}</strong> ({{tutor_email}}) ha intentado inscribir al alumno
   <strong>{{student_name}}</strong> ({{student_email}}) que ya está asignado a otro tutor.</p>
   <p>Por favor, revisa la situación desde el panel de administración.</p>',
  'El tutor {{tutor_name}} ha intentado inscribir al alumno {{student_name}} que ya está asignado a otro tutor.'
)
ON CONFLICT (template_key, language) DO NOTHING;

INSERT INTO public.email_dispatch_rules (event_type, template_key, email_field, name_field, language, active)
VALUES ('STUDENT_CONFLICT', 'STUDENT_CONFLICT', 'admin_email', 'admin_name', 'es', true)
ON CONFLICT DO NOTHING;

GRANT INSERT, UPDATE ON public.email_dispatch_rules TO "elfi1953_stc-eu";
GRANT INSERT, UPDATE ON public.email_templates      TO "elfi1953_stc-eu";
