<?php

namespace App\Repository;

use App\Entity\MemberDocument;
use App\Entity\Member;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<CaseDocument>
 */
class MemberDocumentRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, MemberDocument::class);
    }

    public function removeUnsigned(Member $member)
    {
        $conn = $this->getEntityManager()->getConnection();
        $sql = "DELETE FROM member_document WHERE client_id = :client_id AND client_signed IS NULL";
        $stmt = $conn->prepare($sql);
        $result = $stmt->executeQuery([
            'client_id' => $member->getId()->toBinary()
        ]);

        return $result;
    }

    //    /**
    //     * @return CaseDocument[] Returns an array of CaseDocument objects
    //     */
    //    public function findByExampleField($value): array
    //    {
    //        return $this->createQueryBuilder('m')
    //            ->andWhere('m.exampleField = :val')
    //            ->setParameter('val', $value)
    //            ->orderBy('m.id', 'ASC')
    //            ->setMaxResults(10)
    //            ->getQuery()
    //            ->getResult()
    //        ;
    //    }

    //    public function findOneBySomeField($value): ?CaseDocument
    //    {
    //        return $this->createQueryBuilder('m')
    //            ->andWhere('m.exampleField = :val')
    //            ->setParameter('val', $value)
    //            ->getQuery()
    //            ->getOneOrNullResult()
    //        ;
    //    }
}
