<?php

namespace Technical\Integrations\Providers;

use Technical\Integrations\Database\Seeders\IntegrationsSeeder;
use Technical\Integrations\Support\ProviderRegistry;
use Xefi\LaravelOSDD\LayerServiceProvider;

class IntegrationsServiceProvider extends LayerServiceProvider
{
    public function boot(): void
    {
        if ($this->app->runningInConsole()) {
            $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
            $this->loadSeeders([IntegrationsSeeder::class]);
        }

        $this->withRouting(
            web: __DIR__ . '/../../routes/web.php',
            api: __DIR__ . '/../../routes/api.php',
            commands: __DIR__ . '/../../routes/console.php',
            channels: __DIR__ . '/../../routes/channels.php',
        );
    }

    public function register(): void
    {
        // Singleton partagé : une future couche fournisseur (functional/strava, functional/garmin, ...)
        // récupère ce même registre via app(ProviderRegistry::class)->register(new SonProvider(...))
        // dans son propre boot(), sans jamais modifier cette couche technical/integrations.
        $this->app->singleton(ProviderRegistry::class, fn () => new ProviderRegistry());
    }
}
