<?php
include( $_SERVER['DOCUMENT_ROOT'] . '/logic/userLogic.php' );

$data = "";
$method = "";

$logic = new UserLogic();
$method = 
$result = true;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $json = file_get_contents('php://input');
    $data = json_decode($json, true);
            $result = $logic->handleUserRequests($method, $data);
}


if ($result == null) {
    response('POST', 400, $result);
} else {
    response('POST', 200, $result);
}

function response($method, $status, $data)
{

    header('Content-Type: application/json');
    switch ($method) {
        case 'GET':
            http_response_code($status);
            echo json_encode($data);
            break;
        case 'POST':
            http_response_code($status);
            echo json_encode($data);
            break;
        case 'PUT':
            http_response_code($status);
            echo json_encode($data);
            break;
        case 'DELETE':
            http_response_code($status);
            echo json_encode($data);
            break;
        default:
            http_response_code(400);
            echo json_encode(array("message" => "Invalid method"));
            break;
    }
}

?>