<?php

namespace App\Modules\Notifications;

use Illuminate\Support\Facades\Auth;
use App\Models\ValidationModel;
use App\Models\User;

class NotificationSetting extends ValidationModel
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['user_id', 'notification', 'email', 'alert'];

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'notification_settings';

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

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

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

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

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
