<?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
{
    /**
     * @var \App\Repositories\PouzivatelRepositoryContract
     */
    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 userDeviceTokenStored(Pouzivatel $pouzivatel, string $token): void
    {
        $pouzivatel = $this->pouzivatelRepository->saveNotificationToken($pouzivatel->getKey(), $token);
        $pouzivatelDto = PouzivatelDto::fromModel($pouzivatel);

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