-- Tables pour le module Planning (tâches préventives et correctives)

CREATE TABLE IF NOT EXISTS planning_tasks (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(200) NOT NULL,
  type ENUM('préventive','corrective') NOT NULL DEFAULT 'corrective',
  start_datetime DATETIME NOT NULL,
  end_datetime DATETIME NULL,
  status ENUM('Planifié','En cours','Terminé','Annulé') NOT NULL DEFAULT 'Planifié',
  technician_id INT NULL,
  incident_id INT NULL,
  location_id INT NULL,
  notes TEXT NULL,
  color VARCHAR(7) NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  FOREIGN KEY (technician_id) REFERENCES users(id),
  FOREIGN KEY (incident_id) REFERENCES incidents(id) ON DELETE SET NULL,
  FOREIGN KEY (location_id) REFERENCES locations(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
