<?php

declare(strict_types=1);

namespace CpCreation\AltchaBundle\Security;

use Symfony\Component\Form\FormInterface;

final class ProtectionState
{
    /** @var \WeakMap<FormInterface, true> */
    private \WeakMap $rejected;

    /** @var \WeakMap<FormInterface, true> */
    private \WeakMap $consumed;

    public function __construct()
    {
        $this->rejected = new \WeakMap();
        $this->consumed = new \WeakMap();
    }

    public function reject(FormInterface $form): void
    {
        $this->rejected[$form->getRoot()] = true;
    }

    public function isRejected(FormInterface $form): bool
    {
        return isset($this->rejected[$form->getRoot()]);
    }

    public function markConsumed(FormInterface $form): void
    {
        $this->consumed[$form] = true;
    }

    public function isConsumed(FormInterface $form): bool
    {
        return isset($this->consumed[$form]);
    }
}
