-- MenuMail — Schéma base de données
-- À importer sur OVH via phpMyAdmin

CREATE TABLE IF NOT EXISTS `mm_restaurateurs` (
  `id`           INT AUTO_INCREMENT PRIMARY KEY,
  `nom`          VARCHAR(100) NOT NULL,
  `slug`         VARCHAR(100) NOT NULL UNIQUE,
  `email`        VARCHAR(150) NOT NULL UNIQUE,
  `password`     VARCHAR(255) NOT NULL,
  `restaurant`   VARCHAR(150) NOT NULL,
  `adresse`      VARCHAR(255),
  `actif`        TINYINT(1) DEFAULT 1,
  `cree_le`      DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `mm_abonnes` (
  `id`               INT AUTO_INCREMENT PRIMARY KEY,
  `restaurateur_id`  INT NOT NULL,
  `email`            VARCHAR(150) NOT NULL,
  `nom`              VARCHAR(100),
  `token`            VARCHAR(64) NOT NULL,
  `confirme`         TINYINT(1) DEFAULT 0,
  `cree_le`          DATETIME DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY `unique_abonne` (`restaurateur_id`, `email`),
  FOREIGN KEY (`restaurateur_id`) REFERENCES `mm_restaurateurs`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `mm_menus` (
  `id`               INT AUTO_INCREMENT PRIMARY KEY,
  `restaurateur_id`  INT NOT NULL,
  `date_menu`        DATE NOT NULL,
  `entree`           TEXT,
  `plat`             TEXT NOT NULL,
  `dessert`          TEXT,
  `formule_prix`     DECIMAL(5,2),
  `note`             TEXT,
  `envoye`           TINYINT(1) DEFAULT 0,
  `envoye_le`        DATETIME,
  `cree_le`          DATETIME DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY `unique_menu_jour` (`restaurateur_id`, `date_menu`),
  FOREIGN KEY (`restaurateur_id`) REFERENCES `mm_restaurateurs`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `mm_admin` (
  `id`       INT AUTO_INCREMENT PRIMARY KEY,
  `email`    VARCHAR(150) NOT NULL UNIQUE,
  `password` VARCHAR(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Admin par défaut : admin@menumail.fr / admin123 (à changer !)
INSERT INTO `mm_admin` (`email`, `password`)
VALUES ('admin@menumail.fr', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi');
