<commit_before><?php

namespace App\Repositories;

use App\Models\Eloquent\Notification;

class NotificationRepository extends EloquentRepository
{
    public function __construct(Notification $notification)
    {
        parent::__construct($notification);
    }

    /**
     * Get notifications by user ID
     *
     * @param integer $userId
     * @param boolean $read
     * @param integer $limit
     * @param integer $offset
     *
     * @return array
     */
    public function getForUser($userId, $read, $limit = 20, $offset = 0)
    {
        $query = $this->model->where('user_id', $userId);

        if (!is_null($read)) {
            $query->where('read', (boolean) $read);
        }

        $notifications = $query->take($limit)->skip($offset)->get();

        if (!empty($notifications)) {
            return $notifications->toArray();
        }

        return [];
    }

    /**
     * Mark a specific notification as read/unread
     *
     * @param integer $notificationId
     * @param string $status
     *
     * @return boolean
     */
    public function setRead($notificationId, $status)
    {
        $notification = $this->getById($notificationId);

        if (empty($notification)) {
            return false;
        }
<commit_msg>Added total unread to the api endpoint of notifications<commit_after><?php

namespace App\Repositories;

use App\Models\Eloquent\Notification;

class NotificationRepository extends EloquentRepository
{
    public function __construct(Notification $notification)
    {
        parent::__construct($notification);
    }

    /**
     * Get notifications by user ID
     *
     * @param integer $userId
     * @param boolean $read
     * @param integer $limit
     * @param integer $offset
     *
     * @return array
     */
    public function getForUser($userId, $read, $limit = 20, $offset = 0)
    {
        $query = $this->model->where('user_id', $userId);

        if (!is_null($read)) {
            $query->where('read', $read);
        }

        $notifications = $query->take($limit)->skip($offset)->get();

        $unreadCount = $this->model->where('user_id', $userId)->where('read', 0)->count();

        if (!empty($notifications)) {
            return ['unread' => $unreadCount, 'data' => $notifications->toArray()];
        }

        return ['unread' => 0, 'data' => []];
    }

    /**
     * Mark a specific notification as read/unread
     *
     * @param integer $notificationId
     * @param string $status
     *
     * @return boolean
     */
    public function setRead($notificationId, $status)
    {
        $notification = $this->getById($notificationId);

        if (empty($notification)) {
            return false;
        }

{'fraction_non_alphanumeric': 0.13975726369988967, 'fraction_numerical': 0.002942258183155572, 'mean_word_length': 2.3580246913580245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5440072', 'n_tokens_mistral': 785, 'n_tokens_neox': 763, 'n_words': 177}