<?php

declare(strict_types=1);

namespace Maestro\Core\Support;

final class ModuleDependencyMap
{
    /** @var array<string, list<string>> slug => slugs this module requires */
    private const DEPENDENCIES = [
        'customers' => [],
        'hours'     => ['customers'],
        'offers'    => ['customers'],
        'invoices'  => ['customers'],
        'items'     => ['invoices'],
    ];

    /** @return list<string> */
    public static function dependenciesFor(string $slug): array
    {
        return self::DEPENDENCIES[$slug] ?? [];
    }

    /** @return list<string> Slugs of modules that require this one */
    public static function dependentsOf(string $slug): array
    {
        $dependents = [];
        foreach (self::DEPENDENCIES as $moduleSlug => $deps) {
            if (in_array($slug, $deps, true)) {
                $dependents[] = $moduleSlug;
            }
        }

        return $dependents;
    }

    /** @return list<string> All known module slugs in dependency order */
    public static function allSlugs(): array
    {
        return array_keys(self::DEPENDENCIES);
    }
}
