<?php


    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json");
    header("Accept: application/json");

    require '../config/conn.php';
    
    $uId = $_POST['uId'];
    $coins = $_POST['coins'];
    $activity = $_POST['activity'];
    $paid = $_POST['paid'];

    $updateUserData = "UPDATE `users` SET `coins`=`coins`+'$coins' WHERE `uId`='$uId'";
    $update=mysqli_query($conn,$updateUserData);

    if($update)
    {
        $createPlayingHistory="INSERT INTO `playinghistory` (`id`, `uId`, `icon`, `activity`, `coins`, `paid`, `status`, `type`, `date`) VALUES (NULL, '$uId', '', '$activity', '$coins', '$paid', '1', 'AD REWARD', current_timestamp());";
        $create = mysqli_query($conn,$createPlayingHistory);

        if($create)
        {
            $response['statusCode']=0;
            $response['message']="Successful";
        }
        else
        {
            $response['statusCode']=4;
            $response['message']="Error in creating playing history";
        }
    }
    else
    {
        $response['statusCode']=4;
        $response['message']="Error in updating user coins";  
    }

    echo json_encode($response);



?>