<?php
ini_set('display_errors', 1);

require_once '../resources/base_path_include.php';

require_once $base_path_to_learning_resources  . "includes/connect.php"; // use require for mandatory files

require_once $base_path_to_learning_resources . 'lib/function.php';
require_once $base_path_to_learning_resources . 'lib/validate_api_signature.php';

//valdation file
require_once $base_path_to_learning_resources.'lib/validate_function.php';

require_once $base_path_to_learning.'user_management/authenticate.php';

require_once $base_path_to_learning.'user_management/check_username_availability.php';

$postdata = json_decode(file_get_contents("php://input"), true);
//print_r($postdata);
checkIfNoPhpContentsReceive();
validateApiSignature($postdata['api_signature']);


if ($postdata['function_type'] == "check_username_availability") {
   
    $username = trim($postdata['username']);
    
   $successreturn =checkUsernameAvailabilty($conn_rjllearning, $username);
    if($successreturn == false) {
        
     errorreturn("Username already exists. Please try another username.");
    } else {
    
    return true;
    }
}