<?php

date_default_timezone_set("Africa/Lagos");
require_once '../../vendor/autoload.php';
require_once '../../include/DatabaseConn.php';
require_once '../../models/User.php';
require_once '../../include/Constants.php';

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

$std = new stdClass();

$id = filter_input(INPUT_GET, "user", FILTER_VALIDATE_EMAIL);
$amount = filter_input(INPUT_GET, "amount");
$description = filter_input(INPUT_GET, "description");

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

if (is_null($id)) {
    $error = 'Token missing in request body';
    $std->error = $error;
    echo (json_encode($std));
    die();
} else {
    $paid = APPROVED;
    $time = time();
    $status = REWARD;
    mysqli_query($link, "insert INTO walletR(`user`,amount,`date`,status, description) VALUES('$id',$amount,'$time','$status', '$description')");
    if (mysqli_affected_rows($link) == 1) {
        $std->msg = APPROVED;
        $ref_total = number_format(User::getWalletBalanceR($link, $id));
         User::notify11($id, $description, "Referral Deposit Confirmed");
        echo (json_encode($std));
        die();
    } else {
        $error = 'Already updated';
        $std->error = $error;
        echo (json_encode($std));
        die();
    }
}

