<?php

namespace App\Controllers;

class AlertsController extends BaseController
{
    public function index(): string
    {
        $data = service('alerts')->getIndexData($this->request->getGet(), auth()->user());

        return view('alerts/index', $data);
    }

    public function markRead(int $notificationId)
    {
        $marked = service('alerts')->markNotificationRead($notificationId, auth()->user());

        if (! $marked) {
            return $this->forbidden('Nu poti modifica aceasta notificare.');
        }

        return redirect()->to(url_to('alerts.index'))->with('message', 'Notificarea a fost marcata ca citita.');
    }
}
