<?php

declare(strict_types=1);

namespace App\Notifications\Push;

use Illuminate\Bus\Queueable;
use NotificationChannels\Fcm\FcmMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use NotificationChannels\Fcm\Resources\Notification as FCMNotification;
use Seka\Portal\Core\Notifications\FirebaseCloudMessaging\Channels\FcmChannel;
use Seka\Portal\Core\Notifications\FirebaseCloudMessaging\Messages\MessageDataBuilder;
use Seka\Portal\Core\Notifications\FirebaseCloudMessaging\Messages\Data\Enums\MessageDataTypeEnum;
use Seka\Portal\Core\Notifications\FirebaseCloudMessaging\Messages\Data\Enums\MessageDataMethodEnum;
use Seka\Portal\Core\Notifications\FirebaseCloudMessaging\Messages\Data\Enums\MessageDataSourceEnum;

/**
 * Class MAAISEKUserSendPushNotification
 *
 * @package App\Notifications\Push
 */
final class MAAISEKUserSendPushNotification extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * @var string
     */
    private string $sprava;

    /**
     * @param \App\Dtos\PouzivatelDto $pouzivatel
     */
    public function __construct(string $sprava)
    {
        $this->sprava = $sprava;
    }

    /**
     * @param $notifiable
     *
     * @return string[]
     */
    public function via($notifiable): array
    {
        return [
            FcmChannel::class,
        ];
    }

    /**
     * @return string[]
     */
    public function viaQueues(): array
    {
        return [
            FcmChannel::class => 'push-notifications-queue',
        ];
    }

    /**
     * @param $notifiable
     *
     * @return \NotificationChannels\Fcm\FcmMessage
     * @throws \NotificationChannels\Fcm\Exceptions\CouldNotSendNotification
     */
    public function toFcm($notifiable): FcmMessage
    {
        $data = MessageDataBuilder::make(
            MessageDataSourceEnum::PORTAL_WEB(),
            MessageDataTypeEnum::INTERACTIVE(),
            MessageDataMethodEnum::MAA_SHOW_USER_NOTIFICATION_SCREEN()
        );

        return FcmMessage::create()
            ->setData($data->toArray())
            ->setNotification(
                FCMNotification::create()
                    ->setTitle('Portál')
                    ->setBody($this->sprava)
            );
    }
}
