-- Script SQL para crear la base de datos manualmente
-- Ejecutar esto en MySQL si prefieres no usar el endpoint /api/init-db

CREATE DATABASE IF NOT EXISTS invitacion_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

USE invitacion_db;

CREATE TABLE IF NOT EXISTS invitations (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(255) NOT NULL,
  subtitle VARCHAR(255),
  description TEXT,
  event_date VARCHAR(50),
  event_time VARCHAR(50),
  location VARCHAR(255),
  location_map VARCHAR(500),
  rsvp_phone VARCHAR(30),
  rsvp_allow_update INT DEFAULT 1,
  rsvp_view_token VARCHAR(64),
  max_guests INT DEFAULT NULL,
  music_youtube_url VARCHAR(500),
  music_autoplay INT DEFAULT 1,
  music_banner_url VARCHAR(500),
  theme_type VARCHAR(30) DEFAULT 'xv',
  background_image_url VARCHAR(500),
  background_effect VARCHAR(30) DEFAULT 'none',
  hero_photo_url VARCHAR(500),
  hero_top_text VARCHAR(255),
  hero_display_name VARCHAR(255),
  hero_text_color VARCHAR(50),
  hero_name_color VARCHAR(50),
  welcome_message TEXT,
  guest_name VARCHAR(255),
  image_url VARCHAR(500),
  image_url_2 VARCHAR(500),
  image_url_3 VARCHAR(500),
  color_theme VARCHAR(50) DEFAULT 'purple',
  accent_color VARCHAR(50),
  parent_1_name VARCHAR(255),
  parent_2_name VARCHAR(255),
  dress_code VARCHAR(255),
  reserved_colors VARCHAR(500),
  dress_code_image_url VARCHAR(500),
  gift_text VARCHAR(500),
  gift_image_url VARCHAR(500),
  reception_location VARCHAR(255),
  reception_details VARCHAR(255),
  show_countdown INT DEFAULT 1,
  closing_text VARCHAR(255),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS rsvps (
  id INT AUTO_INCREMENT PRIMARY KEY,
  invitation_id INT NOT NULL,
  family_name VARCHAR(255),
  guest_name VARCHAR(255),
  phone VARCHAR(32),
  guests_count INT DEFAULT 1,
  message_text TEXT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX idx_invitation_id (invitation_id),
  UNIQUE KEY uniq_invitation_phone (invitation_id, phone),
  CONSTRAINT fk_rsvps_invitation FOREIGN KEY (invitation_id) REFERENCES invitations(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Insertar datos de ejemplo
INSERT INTO invitations
(title, subtitle, description, event_date, event_time, location, location_map, rsvp_phone, rsvp_allow_update, max_guests, music_youtube_url, music_autoplay, music_banner_url, theme_type, background_image_url, guest_name, image_url, color_theme, parent_1_name, parent_2_name, dress_code, reception_location, show_countdown)
VALUES (
  'Mrs XV',
  'Melanie Nigella Siliezar Miranda',
  'Te invitamos a celebrar mis 15 años, llenos de amor y alegría',
  '2026-06-15',
  '18:00',
  'Salón de Eventos - Calle Principal 123',
  'https://www.google.com/maps?q=Salón%20de%20Eventos%20Calle%20Principal%20123',
  '50200000000',
  1,
  4,
  'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
  1,
  '',
  'xv',
  '',
  'Estimado Invitado',
  'https://images.unsplash.com/photo-1540575467063-178f50902882?w=800',
  'purple',
  'Cesar Edisomn Siliezar Gonzalez',
  'Yleania Maddy Miranda Guzman',
  'De Gala',
  'Casa MAMA boutique - Cualquier horario',
  1
);
