<?php

namespace App\Listeners;

use App\Events\BugAssigned;
use App\Models\AppNotification;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendBugAssignedNotification implements ShouldQueue
{
    public function handle(BugAssigned $event): void
    {
        if (! $event->bug->assigned_to) {
            return;
        }

        AppNotification::create([
            'user_id' => $event->bug->assigned_to,
            'title' => 'Bug Assigned',
            'message' => 'A new bug has been assigned to you: '.$event->bug->title,
            'type' => 'bug_assignment',
            'status' => 'pending',
            'scheduled_at' => now(),
            'sent_at' => now(),
        ]);
    }
}
