-- 009 (L19-L20): reseñas verificadas por episodio y derivaciones a servicios
CREATE TABLE IF NOT EXISTS resenas (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  user_id BIGINT UNSIGNED NOT NULL,
  cirujano_id BIGINT UNSIGNED NOT NULL,
  episodio_id BIGINT UNSIGNED NOT NULL UNIQUE,
  puntuacion TINYINT NOT NULL,
  texto VARCHAR(1200) NULL,
  estado ENUM('pendiente','publicada','rechazada') NOT NULL DEFAULT 'pendiente',
  moderado_por BIGINT UNSIGNED NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_res (cirujano_id, estado)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS derivaciones (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  user_id BIGINT UNSIGNED NOT NULL,
  servicio_id BIGINT UNSIGNED NOT NULL,
  mensaje VARCHAR(600) NULL,
  estado ENUM('nueva','contactada','cerrada') NOT NULL DEFAULT 'nueva',
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY idx_der (servicio_id, estado)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
