<?php
    /*
            *****************************************************************************
            * MEGA Digital Space - by MEGA Digital Studio                               *
            * ------------------------------------------------------------------------- *
            * CMS Website:  https://megadigital.space                                   *
            * License:  https://megadigital.space/license                               *
            * Owner:  Giorgi Basharuli                                                  *
            * Contact:  online@megadigital.studio                                       *
            * MEGA Digital Studio – Official Development Studio for MEGA Digital Space  *
            * Website:  https://megadigital.studio                                      *
            * ------------------------------------------------------------------------- *
            * Description: This file is a part of the MEGA Digital Space CMS system.    *
            * Unauthorized distribution, modification, or commercial use is strictly -  *
            * prohibited without prior written permission.                              *
            * ------------------------------------------------------------------------- *
            * Copyright (c) 2023-2025 MEGA Digital Studio.                              *
            * All rights reserved.                                                      *
            *****************************************************************************
        */

    require_once($_SERVER["DOCUMENT_ROOT"] . '/engine/data/config.php');
    require_once($_SERVER["DOCUMENT_ROOT"] . "/engine/data/dbconfig.php");

    session_start();

    global $db_connect;

    $user = [];
    if (!empty($_POST["userId"])) {
        $user = $db_connect->get("users", "*", ["id" => $_POST["userId"]]);


        $db_connect->update("user_relationships", ["is_blocked" => 1], ["user_id_to" => $_POST["userId"], "user_id_from" => $_SESSION["user_id"]]);
        $db_connect->update("user_relationships", ["is_blocked" => 1], ["user_id_to" => $_SESSION["user_id"], "user_id_from" => $_POST["userId"]]);

        $usersRelationship = $db_connect->get("user_relationships", "*", ["user_id_from" => $_SESSION["user_id"], "user_id_to" => $_POST["userId"]]) ?? [];

        if ($usersRelationship["is_blocked"] == 1) {
            $user["is_blocked"] = 1;
        } else {
            $user["is_blocked"] = 0;
        }
    }


    echo json_encode($user);