<?php

namespace App\Modules\Notifications;

use App\Models\ValidationModel;

class DesktopNotificationsSetting extends ValidationModel
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'desktop_notifications_settings';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['user_id', 'name', 'value'];

    /**
     * Array of validation rules.
     *
     * @var  array
     */
    protected static $rules = [
        'name'         => 'required',
        'value'        => 'required',
        'user_id'      => 'required',
    ];

    /**
     * Filters all notifications to display only the current user's notifications.
     * 
     * @return query
     */
    public function scopeCurrentUser($query)
    {
        return $query->where('user_id', '=', getAuthUserId());
    }

    public function scopeDesktopNotification($query, $name)
    {
        return $query->where('name', '=', $name);
    }

    public function scopeUser($query, $user)
    {
        return $query->where('user_id', '=', $user);
    }
}
