<?php

declare(strict_types=1);

namespace NoahVet\Reef\Security\Policy;

/**
 * @deprecated
 * @see PolicyManager
 */
class PolicyExecutor
{
    /**
     * @var iterable<PolicyInterface<PolicySubjectInterface>>
     */
    protected iterable $policies;

    /**
     * @param iterable<PolicyInterface<PolicySubjectInterface>> $policies
     */
    public function __construct(
        iterable $policies,
    ) {
        $this->policies = $policies;
    }

    /**
     * @return array<PolicyResult>
     */
    public function execute(mixed $subject): array
    {
        $results = [];

        foreach ($this->policies as $policy) {
            if ($policy->canHandle($subject)) {
                $results[] = $policy->apply($subject);
            }
        }

        return $results;
    }
}
