<?php
// FILE: Pages/lib_notify.php
function send_notification(PDO $pdo, int $user_id, ?int $borrow_id, string $type, string $message, ?string $ref_date = null): bool {
  $sql = "INSERT INTO notifications (user_id, borrow_id, type, message, ref_date, is_read, created_at)
          VALUES (:uid, :bid, :type, :msg, :rdate, 0, NOW())";
  try {
    $stmt = $pdo->prepare($sql);
    return $stmt->execute([
      ':uid' => $user_id,
      ':bid' => $borrow_id,
      ':type'=> $type,                 // STATUS_UPDATE | REMINDER_H1 | REMINDER_OVERDUE
      ':msg' => $message,
      ':rdate'=> $ref_date            // pakai tanggal hari ini utk reminder (unik harian)
    ]);
  } catch (PDOException $e) {
    // kalau kena UNIQUE (reminder dobel), cukup abaikan
    return false;
  }
}
