<?php

require_once '../../vendor/autoload.php';
require_once '../../include/DatabaseConn.php';
require_once '../../include/Constants.php';

$db = new DatabaseConn();
$link = $db->connect();

$std = new stdClass();

$id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
$amount = filter_input(INPUT_GET, "amount", FILTER_VALIDATE_FLOAT);



header("content-type: application/json");

if (is_null($id)) {
    $error = 'Token missing in request body';
    $std->error = $error;
    echo (json_encode($std));
    die();
}
else if (is_null($amount) || is_bool($amount)) {
     $error = 'Invalid amount';
    $std->error = $error;
    echo (json_encode($std));
    die();
}
else {
    mysqli_query($link, "update wallet set amount = $amount where `id` = $id");
    if (mysqli_affected_rows($link) == 1) {
        $std->msg = "Amount updated";
        echo (json_encode($std));
        die();
    } else {
        $error = 'No change';
        $std->error = $error;
        echo (json_encode($std));
        die();
    }
}

