<?php

namespace Modules\SpecialAttendance\Listeners;

use App\Events\AttendanceNotification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Modules\SpecialAttendance\Entities\TardyNotification;

class SendAttendanceNotification implements ShouldQueue
{
    use InteractsWithQueue;

    public function handle(AttendanceNotification $event)
    {
        TardyNotification::create([
            'user_id' => $event->user->id,
            'notification_type' => 'Tardy',
            'message' => 'You have a tardy record. Please appeal if this was due to an emergency.',
            'sent_at' => now(),
        ]);

        $event->tardyRecord->update([
            'is_notified' => true,
            'notified_at' => now(),
        ]);
    }
}
