-- ============================================
-- Script SQL pour créer UNIQUEMENT les tables manquantes
-- Utilisez ce script si certaines tables existent déjà
-- ============================================

-- Table: working_hours (Horaires d'ouverture)
-- CRITIQUE pour corriger les erreurs 500
CREATE TABLE IF NOT EXISTS `working_hours` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `business_id` INT(11) NOT NULL,
  `day_of_week` INT(11) NOT NULL COMMENT '0=Lundi, 6=Dimanche',
  `open_time` TIME DEFAULT NULL,
  `close_time` TIME DEFAULT NULL,
  `closed` TINYINT(1) DEFAULT 0,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_business_day` (`business_id`, `day_of_week`),
  FOREIGN KEY (`business_id`) REFERENCES `businesses`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table: blocked_dates (Dates bloquées)
-- CRITIQUE pour corriger les erreurs 500
CREATE TABLE IF NOT EXISTS `blocked_dates` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `business_id` INT(11) NOT NULL,
  `date` DATE NOT NULL,
  `reason` TEXT DEFAULT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_business_date` (`business_id`, `date`),
  FOREIGN KEY (`business_id`) REFERENCES `businesses`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table: option_availability (Disponibilité options par véhicule)
-- CRITIQUE pour corriger les erreurs 500 des options
CREATE TABLE IF NOT EXISTS `option_availability` (
  `option_id` INT(11) NOT NULL,
  `vehicle_type_id` INT(11) NOT NULL,
  PRIMARY KEY (`option_id`, `vehicle_type_id`),
  FOREIGN KEY (`option_id`) REFERENCES `options`(`id`) ON DELETE CASCADE,
  FOREIGN KEY (`vehicle_type_id`) REFERENCES `vehicle_types`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table: option_pricing (Tarifs des options par véhicule)
-- CRITIQUE pour corriger les erreurs 500 des options
CREATE TABLE IF NOT EXISTS `option_pricing` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `option_id` INT(11) NOT NULL,
  `vehicle_type_id` INT(11) NOT NULL,
  `price_ht` DECIMAL(10,2) NOT NULL,
  `price_ttc` DECIMAL(10,2) NOT NULL,
  `duration` DECIMAL(4,2) DEFAULT 0.50,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_option_vehicle` (`option_id`, `vehicle_type_id`),
  KEY `idx_option` (`option_id`),
  KEY `idx_vehicle` (`vehicle_type_id`),
  FOREIGN KEY (`option_id`) REFERENCES `options`(`id`) ON DELETE CASCADE,
  FOREIGN KEY (`vehicle_type_id`) REFERENCES `vehicle_types`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ============================================
-- Fin du script
-- ============================================



