<?php
session_start();
require_once '../../config/database.php';
require_once '../../includes/chat_helper.php';
header('Content-Type: application/json');
if (!isset($_SESSION['csr_id'])) { echo json_encode(['success'=>false,'message'=>'Unauthorized']); exit; }
$request_id = (int)($_POST['request_id'] ?? 0);
$message = trim($_POST['message'] ?? '');
if (!$request_id || $message === '') { echo json_encode(['success'=>false,'message'=>'Message is required.']); exit; }
try {
    $database = new Database(); $db = $database->getConnection(); ensureChatTables($db);
    addSystemChatMessageForRequest($db, $request_id, $message, 'reminder');
    createCustomerNotification($db, $request_id, 'Appointment Reminder', $message, 'info');
    echo json_encode(['success'=>true]);
} catch(Exception $e) { echo json_encode(['success'=>false,'message'=>$e->getMessage()]); }
?>
