<?php

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

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

    $inviteCode = $_POST['inviteCode'];

    //Fetching invite sender reward
    $fetchInviteSenderReward = "SELECT * FROM `rewardsettings` WHERE `id` = 2";
    //Fetching invitee reward
    $fetchInviteeReward = "SELECT * FROM `rewardsettings` WHERE `id` = 3";

    $fetchSenderReward = mysqli_query($conn,$fetchInviteSenderReward);
    $fetchReceiverReward = mysqli_query($conn,$fetchInviteeReward);

    if($fetchSenderReward && $fetchReceiverReward)
    {

        while($row=$fetchSenderReward->fetch_assoc())
        {
            $response['inviteSenderReward'] = $row['value'];
        }

        while($row=$fetchReceiverReward->fetch_assoc())
        {
            $response['inviteReceiverReward'] = $row['value'];
        }

    }
    else
    {
        $response['statusCode'] = 4;
        $response['message'] = 'Error occurred in fetching invite earn reward';
    }

    //Fetch user invitees
    $fetchUserInvitees = "SELECT `id`,`name`,`email`,`avatar` FROM `users` WHERE `invitedBy` = '$inviteCode';";
    $fetchInvitees = mysqli_query($conn,$fetchUserInvitees);

    if($fetchInvitees)
    {
        $response['statusCode'] = 0;
        $response['message'] = 'Successful';
        while($row=$fetchInvitees->fetch_assoc())
        {
            $response['userInvitees'][]=$row;
        }
    }
    else
    {
        $response['statusCode'] = 4;
        $response['message'] = 'Error occurred in fetching user invitees';
    }

    echo json_encode($response);



?>