<?php
// =====================================================
// POST /update-line-man.php
// Body (JSON): { id, name, phone, role, permissions }
// Response: plain text "Update Successful" / "Update Failed"
// =====================================================
require_once 'config.php';

$conn = getConnection();

$json = file_get_contents('php://input');
$data = json_decode($json, true);

$id          = $data['id']          ?? '';
$name        = $data['name']        ?? '';
$phone       = $data['phone']       ?? '';
$role        = $data['role']        ?? 'normal';

if (empty($id)) {
    echo "Update Failed";
    exit;
}

$stmt = $conn->prepare("UPDATE line_man SET name=?, phone=?, role=? WHERE id=?");
$stmt->bind_param("sssi", $name, $phone, $role, $id);

if ($stmt->execute()) {
    echo "Update Successful";
} else {
    echo "Update Failed";
}

$stmt->close();
$conn->close();
