<?php

declare(strict_types=1);

namespace App\Mcp\Tool\Comment;

use App\Entity\Comment;
use App\Mcp\Tool\McpToolHelper;
use Doctrine\ORM\EntityManagerInterface;
use Mcp\Capability\Attribute\McpTool;
use Mcp\Schema\Result\CallToolResult;

#[McpTool(
    name: 'get_unresolved_comments_count',
    description: 'Get the total count of unresolved (open) comments across all entities.',
)]
class UnresolvedCountTool
{
    use McpToolHelper;

    public function __construct(
        private readonly EntityManagerInterface $em,
    ) {}

    public function __invoke(): CallToolResult
    {
        $count = (int) $this->em->getRepository(Comment::class)
            ->createQueryBuilder('c')
            ->select('COUNT(c.id)')
            ->andWhere('c.status = :status')
            ->setParameter('status', 'open')
            ->getQuery()
            ->getSingleScalarResult()
        ;

        return $this->jsonResponse(['count' => $count]);
    }
}
