<?php

declare(strict_types=1);

namespace Seka\Terminy\Listeners\Udalost;

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

/**
 * Class NotificationView
 *
 * @package Seka\Terminy\Listeners\Udalost
 */
final class NotificationView
{
    /**
     * @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';
            $obj->url = route(
                'modul.terminy.frontend.udalosti.udalost.show',
                [
                    'mtUdalostId' => Hasher::encode($notification->data['id'])
                ]
            );

            return $obj;
        }

        return null;
    }
}
