<?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");

    global $db_connect;

    session_start();

    if (!empty($_POST["reasons"]) && !empty($_POST["messageId"])) {

        $message = $db_connect->get("group_messages", "*", ["id" => $_POST["messageId"]]);

        foreach ($_POST["reasons"] as $reason) {

            $db_connect->insert('chat_complaints', [
                "message_id" => $message["id"],
                "reporter_user_id" => $_SESSION["user_id"],
                "reported_user_id" => $message["sender_id"],
                "reason" => $reason,
                "status" => "pending",
                "chat_type" => "group_chat",
                "created_at" => date("Y-m-d H:i:s")
            ]);

        }

        echo true;


    }

    echo false;