<?php

namespace App\Domain\Notification\Listeners;

use App\Domain\Notification\Services\PushNotificationService;
use App\Domain\Training\Events\SessionCancelled;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendSessionCancelledPush implements ShouldQueue
{
    public function __construct(private PushNotificationService $pushService) {}

    public function handle(SessionCancelled $event): void
    {
        $session = $event->session;
        $group = $session->group;

        if (!$group) {
            return;
        }

        $groupName = $group->name_ar ?? 'المجموعة';
        $date = $session->session_date?->format('Y-m-d') ?? '';

        $this->pushService->sendToGroupParticipants(
            $group,
            'إلغاء جلسة',
            "تم إلغاء جلسة {$groupName} يوم {$date}",
            [
                'type' => 'session_cancelled',
                'route' => '/participants/{participant_uuid}/schedule',
                'session_id' => (string) $session->id,
                'group_id' => (string) $group->id,
                'date' => $date,
            ],
            'session.cancelled'
        );
    }
}
