<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Compiler;

final class EventCompilerPaths
{
    public const CACHE_DIR = 'storage/cache/events';
    public const REPORT_FILE = 'storage/reports/r0100/r0100-event-compiler-report.json';
    public const LOCK_FILE = 'storage/reports/r0100/r0100-event-compiler-lock.json';

    public static function cacheFile(string $basePath, string $file): string
    {
        return rtrim($basePath, DIRECTORY_SEPARATOR) . '/' . self::CACHE_DIR . '/' . $file;
    }

    public static function reportFile(string $basePath): string
    {
        return rtrim($basePath, DIRECTORY_SEPARATOR) . '/' . self::REPORT_FILE;
    }

    public static function lockFile(string $basePath): string
    {
        return rtrim($basePath, DIRECTORY_SEPARATOR) . '/' . self::LOCK_FILE;
    }

    public static function ensureDir(string $file): void
    {
        if (!is_dir(dirname($file))) {
            mkdir(dirname($file), 0775, true);
        }
    }
}
