<?php

declare(strict_types=1);

namespace App\Services\PushNotificationsService;

use App\Dtos\PouzivatelDto;
use App\Models\Pouzivatel\Pouzivatel;
use App\Repositories\PouzivatelRepositoryContract;
use App\Notifications\MAAISEKUserActivatedPushNotification;

/**
 * Class FCMPushNotificationsService
 *
 * @package App\Services\PushNotificationsService
 */
final class FCMPushNotificationsService implements PushNotificationsServiceContract
{
    private PouzivatelRepositoryContract $pouzivatelRepository;

    /**
     * @param \App\Repositories\PouzivatelRepositoryContract $pouzivatelRepository
     */
    public function __construct(PouzivatelRepositoryContract $pouzivatelRepository)
    {
        $this->pouzivatelRepository = $pouzivatelRepository;
    }

    /**
     * @param \App\Models\Pouzivatel\Pouzivatel $pouzivatel
     * @param string                            $token
     *
     * @return void
     */
    public function storeUserDeviceToken(Pouzivatel $pouzivatel, string $token): void
    {
        $pouzivatel = $this->pouzivatelRepository->saveNotificationToken($pouzivatel->getKey(), $token);
        $pouzivatelDto = PouzivatelDto::fromModel($pouzivatel);

        $pouzivatel->notify(new MAAISEKUserActivatedPushNotification($pouzivatelDto));
    }
}
