<?php

declare(strict_types=1);

namespace App\Module\Core\Infrastructure;

use App\Module\Core\Domain\Entity\Notification;
use App\Shared\Domain\Contract\NotifierInterface;
use App\Shared\Domain\Contract\UserInterface;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;

final readonly class Notifier implements NotifierInterface
{
    public function __construct(private EntityManagerInterface $em) {}

    public function notify(
        UserInterface $user,
        string $type,
        string $title,
        string $message,
    ): void {
        $notification = new Notification();
        $notification->setUser($user);
        $notification->setType($type);
        $notification->setTitle($title);
        $notification->setMessage($message);
        $notification->setCreatedAt(new DateTimeImmutable());

        $this->em->persist($notification);
        $this->em->flush();
    }
}
