<?php

declare(strict_types=1);

namespace App\Module\Integration\Infrastructure\Doctrine;

use App\Module\Integration\Domain\Entity\TaskBookStackLink;
use App\Module\Integration\Domain\Repository\TaskBookStackLinkRepositoryInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<TaskBookStackLink>
 */
class DoctrineTaskBookStackLinkRepository extends ServiceEntityRepository implements TaskBookStackLinkRepositoryInterface
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, TaskBookStackLink::class);
    }

    public function findById(int $id): ?TaskBookStackLink
    {
        return $this->find($id);
    }

    /**
     * @return TaskBookStackLink[]
     */
    public function findByTaskId(int $taskId): array
    {
        return $this->findBy(['task' => $taskId], ['createdAt' => 'DESC']);
    }
}
