<?php

require_once __DIR__ . '/../connect.php';

// Retrieve and sanitize input parameters
$phone = filterRequest("phone");
$note = filterRequest("note");
$editor = filterRequest("editor");

// Encrypt phone before storing
$encryptedPhone = $encryptionHelper->encryptData($phone);

// SQL query to insert into notesForPassengerService
$sql = "INSERT INTO `notesForPassengerService` (`phone`, `note`, `editor`) 
        VALUES (:phone, :note, :editor)";

// Prepare the statement
$stmt = $con->prepare($sql);
$stmt->bindParam(':phone', $encryptedPhone);
$stmt->bindParam(':note', $note);
$stmt->bindParam(':editor', $editor);

// Execute and respond
$stmt->execute();

if ($stmt->rowCount() > 0) {
    jsonSuccess(null, "Note inserted successfully");
} else {
    jsonError("Failed to insert note");
}
?>