<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\AdminBundle\Controller;

use FOS\HttpCacheBundle\Http\SymfonyResponseTagger;
use Symfony\Contracts\Service\Attribute\Required;

/**
 * Adds a `tagResponse(string|string[] $tags)` helper to admin controllers so
 * they can emit xkey cache tags in the same shape the CMS does (Contao's
 * AbstractController provides the same method in the CMS bundle).
 */
trait TagsResponses
{
    private SymfonyResponseTagger $fosResponseTagger;

    #[Required]
    public function setFosResponseTagger(SymfonyResponseTagger $tagger): void
    {
        $this->fosResponseTagger = $tagger;
    }

    /**
     * @param string|array<string> $tags
     */
    protected function tagResponse(string|array $tags): void
    {
        $this->fosResponseTagger->addTags((array) $tags);
    }
}
