<?php

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

    require '../config/conn.php';

    $uId = $_POST['uId'];

    $getPlayingHistory = "SELECT `id`, `uId`, `icon`, `activity`, `coins`, `paid`, `status`, `type`, UNIX_TIMESTAMP(`date`) FROM `playinghistory` WHERE `uId` = '$uId' AND `coins` != 0 ORDER BY `id` DESC";
    $fetchHistory = mysqli_query($conn,$getPlayingHistory);

    if($fetchHistory)
    {
        if(mysqli_num_rows($fetchHistory)>0)
        {
            $response['statusCode'] = 0;
            $response['message'] = "Successful"; 

            while($row = $fetchHistory->fetch_assoc())
            {
                $response['playingHistoryList'][] = $row;
            }

            //Fethcing ad enabled
            $getAdEnabled = "SELECT * FROM `basicsettings` WHERE `id` = 2";
            $fetchAdEnabled = mysqli_query($conn,$getAdEnabled);

            if($fetchAdEnabled)
            {
                while($row=$fetchAdEnabled->fetch_assoc())
                {
                    $response['adEnabled'] = $row['value'];
                }
            }

            //Fetching native ad id 
            $getNativeAdId = "SELECT * FROM `adsettings` WHERE `id` = 1";
            $fetchNativeAdId = mysqli_query($conn,$getNativeAdId);

            if($fetchNativeAdId)
            {
                while($row=$fetchNativeAdId->fetch_assoc())
                {
                   $response['nativeAdId'] = $row['adId'];
                }
            }

        }
        else
        {
        $response['statusCode'] = 0;
        $response['message'] = "Successful";
        }
    }
    else
    {
        $response['statusCode'] = 4;
        $response['message'] = "Error in fetching playing history";
    }

    echo json_encode($response);

?>