<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Terminy\Listeners\Registracia;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;
use Seka\Portal\Modul\Terminy\Entities\Dtos\RegistraciaDTO;
use Seka\Portal\Modul\Terminy\Events\Registracia\ZrusenaRegistraciaNaUdalost;
use Seka\Portal\Modul\Terminy\Notifications\Registracia\ZrusenaRegistraciaNotifikacia;

/**
 * Class ZrusenaRegistraciaNaUdalostListener
 *
 * @package Seka\Portal\Modul\Terminy\Listeners\Registracia
 */
final class ZrusenaRegistraciaNaUdalostListener implements ShouldQueue
{
    /**
     * @param \Seka\Portal\Modul\Terminy\Events\Registracia\ZrusenaRegistraciaNaUdalost $event
     *
     * @return void
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     * @throws \Spatie\LaravelData\Exceptions\CannotCreateData
     */
    public function handle(ZrusenaRegistraciaNaUdalost $event): void
    {
        $registraciaDTO = RegistraciaDTO::from($event->registracia);

        Notification::send(
            $event->notifiable,
            new ZrusenaRegistraciaNotifikacia($registraciaDTO),
        );
    }
}
