<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Ticket;
use App\Models\Company;
use App\Models\User;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Auth;

class DashboardController extends Controller
{
    public function dashboard()
    {
        $companyId = Session::get('selected_company');
        $company = Company::find($companyId);
        $tickets = Ticket::where('type', 'inbox')
        ->where('to_email', 'LIKE', '%' . $company->domain)
        ->get();
        return view('index', ['tickets' => $tickets]);
    }
    
    public function waiting()
    {
        $companyId = Session::get('selected_company');
        $company = Company::find($companyId);
        $tickets = Ticket::where('status', 'waiting')->where('type', 'chat')->where('to_email', 'LIKE', '%' . $company->domain)->get();
        return view('waiting', ['tickets' => $tickets]);
    }
    
    public function profile()
    {
        $users = User::where('role_id', '!=', 1)->where('id', '!=', Auth::id())->get();
        return view('profile', ['users' => $users]);
    }
}
