<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Schema;

class SmNotification extends Model
{
    use HasFactory;
    public static function notifications()
    {
        $user = Auth()->user();
        if ($user) {
            $query = self::where('user_id', $user->id)
                ->where('role_id', $user->role_id)
                ->where('is_read', 0)
                ->where('active_status', 1);

            if (moduleStatusCheck('University') && Schema::hasColumn('sm_notifications', 'un_academic_id')) {
                $query->where('un_academic_id', getAcademicId());
            } elseif (Schema::hasColumn('sm_notifications', 'academic_id')) {
                $query->where('academic_id', getAcademicId());
            }

            return $query->latest()->get();
        }

    }
}
