<?php

declare(strict_types=1);

namespace App\Notifications;

use App\Dtos\PouzivatelDto;
use Illuminate\Bus\Queueable;
use NotificationChannels\Fcm\FcmChannel;
use NotificationChannels\Fcm\FcmMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Dtos\PushNotifications\MAAISEKG2NotificationDataContainerDTO;
use NotificationChannels\Fcm\Resources\Notification as FCMNotification;

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

    /**
     * @var \App\Dtos\PouzivatelDto
     */
    private PouzivatelDto $pouzivatel;

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

    /**
     * @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
     */
    public function toFcm($notifiable): FcmMessage
    {
        $data = new MAAISEKG2NotificationDataContainerDTO(['screen_type' => 'notification_to_technician',]);

        return FcmMessage::create()
            ->setData($data->toArray())
            ->setNotification(FCMNotification::create()
                ->setTitle('Aktivácia používateľa')
                ->setBody(sprintf('V apke bol aktivovaný používateľ %s.', $this->pouzivatel->cele_meno))
        );
    }
}
