<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\TicketBundle\Action\Ticket\Handler;

use Chill\TicketBundle\Action\Ticket\AddCommentCommand;
use Chill\TicketBundle\Entity\Comment;
use Chill\TicketBundle\Entity\Ticket;
use Doctrine\ORM\EntityManagerInterface;

final readonly class AddCommentCommandHandler
{
    public function __construct(
        private EntityManagerInterface $entityManager,
    ) {}

    public function handle(Ticket $ticket, AddCommentCommand $command): Comment
    {
        $comment = new Comment($command->content, $ticket);

        $this->entityManager->persist($comment);

        return $comment;
    }
}
