<?php

declare(strict_types=1);

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

use Elceka\Laravel\HashId\Hasher;
use Seka\Portal\Modul\Terminy\Notifications\Udalost\ZrusenaUdalostNotifikaciaDB;
use Seka\Portal\Modul\Terminy\Notifications\Udalost\AktualizovanaUdalostNotifikaciaDB;
use Seka\Portal\Modul\Terminy\Notifications\Udalost\ZverejnenaNovaUdalostNotifikaciaDB;

/**
 * Class UdalostNotificationView
 *
 * @package Seka\Portal\Modul\Terminy\Listeners\Udalost
 */
final class UdalostNotificationView
{
    /**
     * @param $notification
     *
     * @return object|null
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function handle($notification): ?object
    {
        if (
            is_a(AktualizovanaUdalostNotifikaciaDB::class, $notification->type, true)
            || is_a(ZverejnenaNovaUdalostNotifikaciaDB::class, $notification->type, true)
            || is_a(ZrusenaUdalostNotifikaciaDB::class, $notification->type, true)
        ) {
            $obj = new \stdClass();
            $obj->name = 'Terminy::partials.notification-udalost';
            $obj->url = route(
                'modul.terminy.frontend.udalosti.udalost.show',
                [
                    'mtUdalostId' => Hasher::encode($notification->data['id'])
                ]
            );

            return $obj;
        }

        return null;
    }
}
