<?php

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\ContactMessageModel;

/** الرسائل الواردة من فورم "اتصل بنا" بالموقع الإلكتروني العام */
class ContactMessageController extends BaseController
{
    public function index()
    {
        $model = new ContactMessageModel();
        $messages = $model->forCompany($this->currentCompanyId())->orderBy('created_at', 'DESC')->paginate(20);

        return view('admin/contact_messages/index', ['messages' => $messages, 'pager' => $model->pager]);
    }

    public function markRead($id)
    {
        (new ContactMessageModel())->update($id, ['is_read' => 1]);
        return redirect()->back();
    }

    public function delete($id)
    {
        (new ContactMessageModel())->delete($id);
        return redirect()->to('/admin/contact-messages')->with('message', lang('App.deleted_successfully'));
    }
}
