<?php

namespace App\Repositories;

use DateTime;
use DateInterval;
use Illuminate\Database\Eloquent\Model;

class CourseNotification extends Model
{
	protected $dates = ['deleted_at'];

	protected $guarded = ['id'];

	public function learning_product()
	{
		return $this->belongsTo(LearningProduct::class);
	}

	public function scopeNotExpired($query)
	{
		return $query->where('date', '>', new DateTime());
	}

	public function scopeExpired($query)
	{
		return $query->where('date', '<', new DateTime());
	}

	public function scopeExpireInFiveMinutes($query)
	{
		$minutes_to_add = 5;
		$time = new DateTime();
		$time->add(new DateInterval('PT' . $minutes_to_add . 'M'));
		// $stamp = $time->format('Y-m-d H:i');

		return $query->where('date', '<', $time);
	}

	public function scopeNotSent($query)
	{
		return $query->where('sent', false);
	}
}
