<?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\Tests\Action\Comment\Handler;

use Chill\TicketBundle\Action\Comment\Handler\UpdateCommentDeletedStatusCommandHandler;
use Chill\TicketBundle\Action\Comment\UpdateCommentDeletedStatusCommand;
use Chill\TicketBundle\Entity\Comment;
use Chill\TicketBundle\Entity\Ticket;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

/**
 * @internal
 *
 * @coversNothing
 */
class UpdateCommentDeletedStatusCommandHandlerTest extends TestCase
{
    use ProphecyTrait;

    public function testUpdateCommentDeletedStatus(): void
    {
        $handler = $this->buildCommand();

        $ticket = new Ticket();
        $comment = new Comment('content', $ticket);

        // Initially, the comment should not be deleted
        self::assertFalse($comment->isDeleted());

        // Test setting deleted to true
        $command = new UpdateCommentDeletedStatusCommand(delete: true);
        $handler->handle($comment, $command);
        self::assertTrue($comment->isDeleted());

        // Test setting deleted back to false
        $command = new UpdateCommentDeletedStatusCommand(delete: false);
        $handler->handle($comment, $command);
        self::assertFalse($comment->isDeleted());
    }

    private function buildCommand(): UpdateCommentDeletedStatusCommandHandler
    {
        return new UpdateCommentDeletedStatusCommandHandler();
    }
}
