<?php

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

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

    $uId = $_POST['uId'];

    $getUserData = "SELECT `coins` FROM `users` WHERE `uId` = '$uId'";
    $fetchUserData = mysqli_query($conn,$getUserData);

    if($fetchUserData)
    {
        while($row=$fetchUserData -> fetch_assoc())
        {
            $response['coins'] = $row['coins'];
        }
        //Fetching minimum withdraw limit
        $getMinimumLimit = "SELECT * FROM `basicsettings` WHERE `id` = 4";
        $fetchLimit = mysqli_query($conn,$getMinimumLimit);

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

        //Fetching maximum withdraw time
        $getWithdrawMaximumTime = "SELECT * FROM `basicsettings` WHERE `id` = 5";
        $fetchMaximumTime = mysqli_query($conn,$getWithdrawMaximumTime);

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

        //Fetching Conversion Rate
        $getConversionRate = "SELECT * FROM `basicsettings` WHERE `id` = 6";
        $fetchConversion = mysqli_query($conn,$getConversionRate);

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


        //Fetching Withdarw Methods
        $getWithdrawMethods = "SELECT * FROM `withdrawmethods` WHERE `enabled` = 1";
        $fetchMethods = mysqli_query($conn,$getWithdrawMethods);

        if($fetchMethods)
        {
            while($row=$fetchMethods->fetch_assoc())
            {
                $response['withdrawMethods'][] = $row;
            }
        }
    }

    if($fetchLimit && $fetchMaximumTime && $fetchMethods)
    {
        $response['statusCode'] = 0;
        $response['message'] = "Successful";
    }
    else
    {
        $response['statusCode'] = 4;
        $response['message'] = "Some error ocurred";
    }

    echo json_encode($response);



?>