CREATE DATABASE IF NOT EXISTS webt7708_convitesonline_db;
USE webt7708_convitesonline_db;

CREATE TABLE IF NOT EXISTS event_gallery (
    id INT AUTO_INCREMENT PRIMARY KEY,
    event_id INT NOT NULL,
    image_path VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS rsvps (
    id INT AUTO_INCREMENT PRIMARY KEY,
    event_id INT NOT NULL,
    name VARCHAR(255) NOT NULL,
    whatsapp VARCHAR(20),
    status ENUM('Sim', 'Não', 'Talvez') NOT NULL,
    guest_count INT DEFAULT 0,
    guest_names TEXT,
    note TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS plans (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    price DECIMAL(10, 2) NOT NULL,
    event_limit INT,
    confirmation_limit INT,
    validity_days INT, -- days the invitation stays active
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    site_name VARCHAR(100) DEFAULT 'webTHI Convites Online',
    logo VARCHAR(255) DEFAULT '/img/logo.png',
    favicon VARCHAR(255) DEFAULT '/favicon.ico',
    support_whatsapp VARCHAR(20),
    primary_color VARCHAR(7) DEFAULT '#ff6a00',
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

INSERT IGNORE INTO settings (id, site_name, logo, favicon) VALUES (1, 'webTHI Convites Online', '/img/logo.png', '/favicon.ico');

-- Insert default plans
INSERT IGNORE INTO plans (id, name, price, event_limit, confirmation_limit, validity_days) VALUES 
(1, 'Básico', 49.90, 1, 50, 15),
(2, 'Premium', 89.90, 3, 300, 60),
(3, 'Profissional', 149.90, -1, -1, 3650);
