<?php

/*
 * This file is part of the Serenity package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Doctrine\Filter;

use CpCreation\VitiCore\Behavior\HasDisable;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Filter\SQLFilter;

/**
 * @author Colinet Julien
 */
final class DisableFilter extends SQLFilter
{
    public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias): string
    {
        foreach ($targetEntity->getReflectionClass()->getInterfaces() as $interface) {
            if (HasDisable::class === $interface->getName()) {
                return "{$targetTableAlias}.disabled = FALSE";
            }
        }

        return '';
    }
}
