<?php
// =====================================================
// POST /add-line-man.php
// Params: name, phone, password, role, permissions
// Response: { status, message }
// =====================================================
require_once 'config.php';

$conn = getConnection();

$name        = $_POST['name']        ?? '';
$phone       = $_POST['phone']       ?? '';
$password    = $_POST['password']    ?? '';
$role        = $_POST['role']        ?? 'normal';

if (empty($name) || empty($phone) || empty($password)) {
    echo json_encode(["status" => "error", "message" => "Name, phone and password are required"]);
    exit;
}

$stmt = $conn->prepare("INSERT INTO line_man (name, phone, password, role) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $name, $phone, $password, $role);

if ($stmt->execute()) {
    echo json_encode(["status" => "success", "message" => "Line man added successfully"]);
} else {
    echo json_encode(["status" => "error", "message" => "Failed to add line man"]);
}

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