<?php

namespace AutoAdmin\Bundle\Core\Cache;

use Symfony\Component\Cache\Adapter\FilesystemAdapter;

class CacheAdapterConfigurator
{
    const CACHE_NS = 'aa.cache';

    public const LIFE_TIME_NONE = 0;

    public const LIFE_TIME_24H = 3600 * 24;

    public function __construct(
        protected string $projectDirectory,
    ) {
    }

    /*
     * permit to override lifetime or other defaults using options array
     */
    public function configure(array $options = []): FilesystemAdapter
    {
        $options = [
            'cache_namespace' => self::CACHE_NS,
            'directory' => $this->projectDirectory.'/var/cache/autoadmin',
            'lifetime' => self::LIFE_TIME_NONE,
            ...$options,
        ];

        return new FilesystemAdapter(
            $options['cache_namespace'],
            $options['lifetime'],
            $options['directory'],
        );
    }
}