<?php

use MintyPHP\App\AppContainer;
use MintyPHP\App\Container\Registrars\AccessRegistrar;
use MintyPHP\App\Container\Registrars\AppServicesRegistrar;
use MintyPHP\App\Container\Registrars\AuthRegistrar;
use MintyPHP\App\Container\Registrars\DirectoryRegistrar;
use MintyPHP\App\Container\Registrars\RepositoryFactoryRegistrar;
use MintyPHP\App\Container\Registrars\ServiceFactoryRegistrar;
use MintyPHP\App\Container\Registrars\SettingsRegistrar;
use MintyPHP\App\Container\Registrars\UserRegistrar;

$container = new AppContainer();

// Order matters: RepositoryFactoryRegistrar and ServiceFactoryRegistrar must run first
// because later registrars pull concrete services from those factories.
$registrars = [
    new RepositoryFactoryRegistrar(),   // raw repository factories (no deps)
    new ServiceFactoryRegistrar(),      // service factories wired with their repo/gateway deps
    new AccessRegistrar(),              // RBAC: permissions, roles, authorization
    new AuthRegistrar(),               // authentication, SSO, tokens
    new DirectoryRegistrar(),           // tenants, departments, scope
    new UserRegistrar(),               // user services and repositories
    new SettingsRegistrar(),           // settings, branding
    new AppServicesRegistrar(),        // leaf services (stats, search, mail, scheduler, ...)
];

foreach ($registrars as $registrar) {
    $registrar->register($container);
}

return $container;
