<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
require_once "../../../config.php";
require_once "../../../validation.php";
require_once "../../../Helper.php";
require_once '../../database1.php';

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

class getChats extends database
{
   	public function unattendedChats()
    {
        $sql = ' SELECT cc.*, p.cl_name FROM tb_chat_customer cc LEFT JOIN tb_product p ON p.cl_id=cc.cl_product_id WHERE (cc.cl_status="Chat Started" OR cc.cl_status="Requested") AND cc.cl_agent_id=0 ORDER BY cc.cl_created_at DESC ';
        return $this->callQuery($sql);
        //return $this->fetchAll('tb_chat_customer', ['cl_status' => 'Chat Started', 'cl_agent_id' => 0], 'cl_created_at', 'DESC');
    }

    public function unfinishedChats($userID)
    {
        $sql = ' SELECT cc.*, p.cl_name FROM tb_chat_customer cc LEFT JOIN tb_product p ON p.cl_id=cc.cl_product_id WHERE (cl_status="Chat Started") AND cl_agent_id=? ORDER BY cl_created_at DESC ';

        $where[] = $userID;
        return $this->callQuery($sql, $where);
        //return $this->fetchAll('tb_chat_customer', ['cl_status' => 'Chat Started', 'cl_agent_id' => $userID], 'cl_created_at', 'DESC');
    }
}


$obj = new getChats();   
$chats['unattendedChats'] = $obj->unattendedChats();
$chats['unfinishedChats'] = $obj->unfinishedChats($userID);



echo json_encode($chats);