<?php
session_start();
require_once "../../../config.php";
require_once "../../../validation.php";
require_once "../../../Helper.php";
require_once '../../database1.php';

require_once "../../check_admin.php";

class addUser extends database
{
	public function insertData($data)
	{
    	return $this->insert('tb_chat', $data);
	}
}

if(!isset($_POST['message']) || !isset($_GET['id']) || !is_numeric($_GET['id']))
{
	http_response_code(400);
	echo json_encode(array('error_text' => 'No input found'));
	exit;
}

$obj = new addUser();

$message = $_POST['message'];

if(trim($message) == '')
{
	$result['error_description']['message'] = 'Please enter any message';
	$result['error_text'] = 'Please enter any message';

	http_response_code(400);
	echo json_encode($result);
	exit;
}



$data['cl_chat_cutomer_id'] = trim($_GET['id']);
$data['cl_user_type'] = 'Agent';
$data['cl_user_id'] = $userID;
$data['cl_message'] = $message;


$chatUserID = $obj->insertData($data);
if(!$chatUserID)
{
	http_response_code(500);
	echo json_encode(array('error_text' => 'Unsuccessful submitting message. Retry.'));
	exit;
}

    
http_response_code(200);
echo json_encode(array('message' => 'Message Added Successfully'));
exit;
